Created
June 2, 2011 19:52
-
-
Save peterbraden/1005153 to your computer and use it in GitHub Desktop.
Arduino to Traffic Light
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
int incomingByte = 0; | |
int prev = 0; | |
int RED = 13; | |
int ORANGE = 12; | |
int GREEN = 11; | |
void setup() { | |
pinMode(RED, OUTPUT); | |
pinMode(ORANGE, OUTPUT); | |
pinMode(GREEN, OUTPUT); | |
Serial.begin(9600); | |
Serial.println("Connected"); | |
} | |
void reset(){ | |
digitalWrite(RED, LOW); | |
digitalWrite(ORANGE, LOW); | |
digitalWrite(GREEN, LOW); | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
incomingByte = Serial.read(); | |
Serial.print("I received: "); | |
Serial.println(incomingByte, DEC); | |
if (incomingByte != prev){ | |
prev = incomingByte; | |
if (incomingByte == 114){ | |
reset(); | |
digitalWrite(RED, HIGH); | |
} | |
if (incomingByte == 103){ | |
reset(); | |
digitalWrite(GREEN, HIGH); | |
} | |
if (incomingByte == 111){ | |
reset(); | |
digitalWrite(ORANGE, HIGH); | |
} | |
if (incomingByte == 120){ | |
reset(); | |
} | |
} | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment