

Try to make it so that the light cycling speed can change at almost any time.
Here's some code to get you started. You can use or ignore my suggested structure in the loop function:
/* Traffic Lights * Solution by: * * This is a simple traffic light simulator. * * During the day, when the walk button (the bottom one) is pressed, the light turns * green so you can walk. Then it cycles back to red. * * At night, when there is little traffic, the button does nothing and the light * blinks red to act as a simple stop signal. * * The potentiometer controls the speed at which the light cycles. * */ // Symbolic names for our pins. const int pot_sense = A0; const int light_sense = A1; const int walkButton = 2; const int button2 = 3; const int red = 13; const int yellow = 12; const int green = 10; // variable for light speed int light_spd = 500; void setup() { // Configure inputs pinMode(pot_sense, INPUT); pinMode(light_sense, INPUT); pinMode(walkButton, INPUT); pinMode(button2, INPUT); // Configure outputs pinMode(red, OUTPUT); pinMode(yellow, OUTPUT); pinMode(green, OUTPUT); // Setting up Serial communication, just in case. Serial.begin(9600); } void loop() { //Get the speed the light will cycle at //if it is night { //the traffic light blinks red } //otherwise it must be day { //So the traffic light will show solid red by default //if the "walk" button is pressed { //Show green for a bit //Show yellow for a bit //Show red for a bit } } }
Challenge idea courtesy of Dr. David Gerhard.