Created
May 14, 2017 17:57
-
-
Save giljr/6d346bc2c2c97f0d6812ec8475e484e7 to your computer and use it in GitHub Desktop.
The garages are getting more and more tight: page: https://goo.gl/pj20lS
This file contains hidden or 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
#define trigPin 13 | |
#define echoPin 12 | |
#define stop_LED 11 | |
#define go_LED 10 | |
void setup() { | |
pinMode(trigPin, OUTPUT); | |
pinMode(echoPin, INPUT); | |
pinMode(stop_LED, OUTPUT); | |
pinMode(go_LED, OUTPUT); | |
} | |
void loop() { | |
long duration, distance; | |
digitalWrite(trigPin, LOW); // Added this line | |
delayMicroseconds(2); // Added this line | |
digitalWrite(trigPin, HIGH); | |
// delayMicroseconds(1000); - Removed this line | |
delayMicroseconds(10); // Added this line | |
digitalWrite(trigPin, LOW); | |
duration = pulseIn(echoPin, HIGH); | |
distance = (duration ) / 58.2; | |
if (distance < 5) { // This is where the LED On/Off happens | |
digitalWrite(stop_LED, HIGH); // When the Red condition is met, the Green LED should turn off | |
digitalWrite(go_LED, LOW); | |
} | |
else { | |
digitalWrite(stop_LED, LOW); | |
digitalWrite(go_LED, HIGH); | |
} | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment