-
-
Save neosarchizo/0585cf26d56653a8ee13 to your computer and use it in GitHub Desktop.
[아두이노, 상상을 현실로 만드는 프로젝트 입문편] 코드 10 - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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