Hi all.
Newbie to this fancy programming stuff you got going here. Have spent days looking on the forums for help with this.
I have been on this problem for 5 day and serious thinking on why I pick this as a new hobby.
Anyhooooo, can anyone help me help me with my simple traffic lights? My program has bits and pieces of other examples.
I want "greenw" to flash 10 times then go "redw" using "IF".
Any suggestions?
int red = 10;
int yellow = 9;
int green = 8;
int redw = 11;
int greenw = 12;
int button = 13; // switch is on pin 12
int DELAY_15DB = 15;
int DELAY_25BK = 350;
int DELAY_HALFSEC = 500;
int DELAY_1SEC = 1000;
int DELAY_2SEC = 2000;
int DELAY_3SEC = 3000;
int DELAY_4SEC = 4000;
int DELAY_5SEC = 5000;
int DELAY_8SEC = 8000;
int DELAY_15SEC = 15000;
int maxnum = 5; // Blink the LED
int count = 0; // Our blink counter
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(redw, OUTPUT);
pinMode(greenw, OUTPUT);
pinMode(button, INPUT);
digitalWrite(green, HIGH);
digitalWrite(redw, HIGH);
}
// ***** This bit for Pedestrian push button
//void loop() {
// if (digitalRead(button) == HIGH){
// delay(15); // software debounce
//if (digitalRead(button) == HIGH) {
// if the switch is HIGH, ie. pushed down - change the lights!
// changeLights();
//delay(DELAY_15SEC); // wait for 15 seconds
//}
//}
//}
//****This bit for non stop
void loop()
{
changeLights();
delay(DELAY_2SEC);
}
void changeLights()
{
//green off, yellow on for 3 seconds
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(DELAY_3SEC);
//turn off yellow, then turn on red for 3 seconds
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(DELAY_3SEC);
// turn on green walk, and turn off red walk for 8 seconds
digitalWrite(greenw, HIGH);
digitalWrite(redw, LOW);
delay(DELAY_3SEC);
// Blink green walk, and turn on red walk
{
if (count > 4)
digitalWrite(redw, HIGH);
delay(DELAY_HALFSEC);
digitalWrite(redw, LOW);
count=0;
}
{ if (count < maxnum)
digitalWrite(greenw, LOW); // set the LED on
delay(350); // wait for a second
digitalWrite(greenw, HIGH); // set the LED off
delay(350); // wait for a second
//Serial.print(count);
count++; // add one (1) to our count
}
//turn on green, then turn off red
digitalWrite(redw, HIGH);
digitalWrite(greenw, LOW);
delay(DELAY_3SEC);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
}