Skip to content

Instantly share code, notes, and snippets.

@peterbraden
Created June 2, 2011 19:52
Show Gist options
  • Save peterbraden/1005153 to your computer and use it in GitHub Desktop.
Save peterbraden/1005153 to your computer and use it in GitHub Desktop.
Arduino to Traffic Light
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