Last active
August 29, 2015 13:56
-
-
Save kiang/8866661 to your computer and use it in GitHub Desktop.
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
int green_time = 10; // seconds to keep green light | |
float yellow_time = 0.5; // seconds to delay flash time | |
int flash_times = 5; // times to flash green light | |
int red1 = 11; | |
int yellow1 = 12; | |
int green1 = 13; | |
int red2 = 3; | |
int yellow2 = 4; | |
int green2 = 5; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize the digital pin as an output. | |
pinMode(red1, OUTPUT); | |
pinMode(green1, OUTPUT); | |
pinMode(yellow1, OUTPUT); | |
pinMode(red2, OUTPUT); | |
pinMode(green2, OUTPUT); | |
pinMode(yellow2, OUTPUT); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
//at first, turn on red1 and green2 | |
digitalWrite(green2, HIGH); | |
digitalWrite(red1, HIGH); | |
delay(1000 * green_time); | |
digitalWrite(green2, LOW); | |
//flash yellow2 | |
for(int i = 0; i < flash_times; i++) { | |
digitalWrite(yellow2, HIGH); | |
delay(1000 * yellow_time); | |
digitalWrite(yellow2, LOW); | |
delay(1000 * yellow_time); | |
} | |
//turn off yellow2, red1 and turn on red2, green1 | |
digitalWrite(red1, LOW); | |
digitalWrite(red2, HIGH); | |
digitalWrite(green1, HIGH); | |
delay(1000 * green_time); | |
digitalWrite(green1, LOW); | |
//flash yellow1 | |
for(int i = 0; i < flash_times; i++) { | |
digitalWrite(yellow1, HIGH); | |
delay(1000 * yellow_time); | |
digitalWrite(yellow1, LOW); | |
delay(1000 * yellow_time); | |
} | |
//turn off red2 and red1, green2 will be turned on on next loop | |
digitalWrite(red2, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment