Simple code .. doesnt work :/

Hi to all .. new to this forum .. my first topic :). i will be fast ... i am working on learning Arduino and have some Traffic light project .. To make it simple i want to make, when you press button the yellow light just blink 2 times .. else .. it works like traffic light .. 5 sec Green 2 sec Yellow 5 sec Red. But for some reason when i press Button, nothing happens. The the LED's just go trough 5sec,2sec,5sec loop .. is like if doesnt work. :confused:

I try to make it with onlye 1 LED .. when you press button the LED goes on .. and it works. So i presume that my breadboard setup if ok ...

int kLedPinPesRED = 8;
int kLedPinPesGREE = 9;
int kLedPinAutRed = 10;
int kLedPinAutYellow = 11;
int kLedPinAutGreen = 12;
int BUTTON = 4;

void setup ()

{
pinMode (kLedPinPesRED, OUTPUT);
pinMode (kLedPinPesGREE, OUTPUT);
pinMode (kLedPinAutRed, OUTPUT);
pinMode (kLedPinAutYellow, OUTPUT);
pinMode (kLedPinAutGreen, OUTPUT);
pinMode (BUTTON, INPUT);

}

void loop ()

{
if(digitalRead(BUTTON) == HIGH)
{
digitalWrite (kLedPinAutRed, LOW);
digitalWrite (kLedPinAutYellow, HIGH);
digitalWrite (kLedPinAutGreen, LOW);
delay(100);
digitalWrite (kLedPinAutRed, LOW);
digitalWrite (kLedPinAutYellow, LOW);
digitalWrite (kLedPinAutGreen, LOW);
delay(100);
digitalWrite (kLedPinAutRed, LOW);
digitalWrite (kLedPinAutYellow, HIGH);
digitalWrite (kLedPinAutGreen, LOW);
delay(100);
digitalWrite (kLedPinAutRed, LOW);
digitalWrite (kLedPinAutYellow, LOW);
digitalWrite (kLedPinAutGreen, LOW);
delay(100);

}

else

{
digitalWrite (kLedPinAutRed, HIGH);
digitalWrite (kLedPinAutYellow, LOW);
digitalWrite (kLedPinAutGreen, LOW);
delay(5000);
digitalWrite (kLedPinAutRed, LOW);
digitalWrite (kLedPinAutYellow, HIGH);
digitalWrite (kLedPinAutGreen, LOW);
delay(2000);
digitalWrite (kLedPinAutRed, LOW);
digitalWrite (kLedPinAutYellow, LOW);
digitalWrite (kLedPinAutGreen, HIGH);
delay(5000);
digitalWrite (kLedPinAutRed, LOW);
digitalWrite (kLedPinAutYellow, HIGH);
digitalWrite (kLedPinAutGreen, LOW);
delay(2000);

}
}

How long are you pressing the button for?

Try holding the button for 14 seconds. That is the sum of the delays.

And that is why delay is bad.

.. Hmm .. didnt think of that .. by the way .. why is there a "sum of delay" is't the "if" command like a trigger for else .. Or .. how would you write this code so that there is no delay for .. Also .. yeah i test it . afther 14 sec .. my circuit with LED's work .. :?

When button is not HIGH it takes the else path and then it is stuck in that path for 14 seconds (the sum of the delays) before it can go back to the top of the loop and look at the button again.

Steve

widuljewic:
.. Hmm .. didnt think of that .. by the way .. why is there a "sum of delay" is't the "if" command like a trigger for else .. Or .. how would you write this code so that there is no delay for .. Also .. yeah i test it . afther 14 sec .. my circuit with LED's work .. :?

Check your keyboard. Something seems to be wrong with the period key. You keep getting multiples and they're getting substituted for all kinds of punctuation. It makes it a bit hard to read.

Next, go look at the Blink Without Delay example and any of the thousands of great tutorials about it.

See this link and everything under "General Design" http://forum.arduino.cc/index.php?topic=384198.0

Ty all for spending time to answer this :),