Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Last active November 8, 2015 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosarchizo/0585cf26d56653a8ee13 to your computer and use it in GitHub Desktop.
Save neosarchizo/0585cf26d56653a8ee13 to your computer and use it in GitHub Desktop.
[아두이노, 상상을 현실로 만드는 프로젝트 입문편] 코드 10 - 1
void setup() {
pinMode(2, OUTPUT);
pinMode(3, INPUT);
}
void loop() {
analogWrite(11, 0);
analogWrite(10, 0);
analogWrite(9, 0);
digitalWrite(2, HIGH);
delayMicroseconds(10);
digitalWrite(2, LOW);
long duration = pulseIn(3, HIGH);
if (duration == 0) {
return;
}
long distance = duration / 58.2;
if (distance < 10) {
analogWrite(11, 255);
} else if (distance < 20) {
analogWrite(10, 255);
} else if (distance < 30) {
analogWrite(9, 255);
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment