Created
May 14, 2017 18:01
-
-
Save giljr/65689977f1e5f9ed3e31b3aaacb9ac26 to your computer and use it in GitHub Desktop.
Garages are getting tighter and tighter: 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
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(2, 3); // RX, TX | |
char data = 0; // Variable for storing | |
#define trigPin 13 | |
#define echoPin 12 | |
#define stop_LED 11 | |
#define go_LED 10 | |
void setup() { | |
Serial.begin(9600); | |
mySerial.begin(9600); | |
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 | |
Serial.println("STOP"); | |
mySerial.println("STOP"); // S - TOP | |
mySerial.println(distance); | |
digitalWrite(go_LED, LOW); | |
} | |
else { | |
digitalWrite(stop_LED, LOW); | |
//mySerial.print('G'); // G - O | |
digitalWrite(go_LED, HIGH); | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment