Stupid question from very beginner:Need help with trafficlight

Hello, I just get my hand on arduino not for long And i just trying this basic program Trafficlight
And im just following this guide

I mean right now when the program start it's stuck at green and its not going nowhere Y nor R But if i push the button it'll go to Y then R

This is the way i want it to be
1.the program start
2.the light go from Y 3sec > R 5sec > Y 2sec and then G and repeat the same
3.then IF i push the button wherever the light is at it'll go to Y > R > Y > G and then end loop
4.And it'll go back to 2. operate itself repeat, And wait until i push the button and it'll go to 3. again


This is my code

int button = 2; 
int buttonValue = 0; 
int redlight = 13; 
int yellowlight = 12; 
int greenlight = 11; 

void setup(){
pinMode(redlight,OUTPUT); 
pinMode(yellowlight,OUTPUT); 
pinMode(greenlight,OUTPUT); 
pinMode(button,INPUT); 
digitalWrite(greenlight,HIGH); 
}

void loop(){
buttonValue = digitalRead(button); 
if (buttonValue == HIGH){ 
LightsChange(); 
delay(15000); 
}
}

void LightsChange(){
digitalWrite(greenlight,LOW);
digitalWrite(yellowlight,HIGH);
delay(3000); 

digitalWrite(yellowlight,LOW);
digitalWrite(redlight,HIGH);
delay(5000); 

digitalWrite(yellowlight,HIGH);
delay(2000); 

digitalWrite(yellowlight,LOW);
digitalWrite(redlight,LOW);
digitalWrite(greenlight,HIGH); 
}

Thank you
ps,I'm not good at english at all ,I'm very sorry about that.

I know arduino boards say plug and play but there is a little more to that. its not like making a salad you need to do more research. good luck

I mean right now when the program start it's stuck at green and its not going nowhere Y nor R But if i push the button it'll go to Y then R

As you do not call the LightsChange() function unless the button is pressed then why are you surprised that they do not change ?

How is the button wired ? Have you got a pulldown resistor attached to the pin to keep it in a known state or is is at a floating (uncertain) voltage ?

Leonides123:
I know arduino boards say plug and play but there is a little more to that. its not like making a salad you need to do more research. good luck

Thank you for your answer

Yeah you're right maybe i'm not trying hard enough

i'm kinda stuck at this for a day now

So i'm just though that maybe someone can point me out or somehow show me the way

I mean right now everything work fine as i've ever expected it to be

But one thing that seems to be a problem is just that so..

Anyway thanks for your answer :wink:

UKHeliBob:
As you do not call the LightsChange() function unless the button is pressed then why are you surprised that they do not change ?

How is the button wired ? Have you got a pulldown resistor attached to the pin to keep it in a known state or is is at a floating (uncertain) voltage ?

I'm really sorry. Well how can i tell you i'm not quite good at english
But yes i'm kinda surprised by the greenlight always on and its not going nowhere
Only thing i want from it is that when the program start i want it to operate by itself as the void LightsChange is set not just stuck at greenlight and wait order from the button
And yes the button wired is correct i'm sure

Surprised that no one has mentioned that you need to put your code in code tags when posting code here

read this: Read this before posting a programming question ... - Programming Questions - Arduino Forum

Things that you want to happen repeatably without input(pushing the button) need to go in void loop().

the delay() function is going to give you trouble because nothing can happen during a delay

these tutorials should help also:

http://forum.arduino.cc/index.php?topic=223286.0

.

Hutkikz:
Surprised that no one has mentioned that you need to put your code in code tags when posting code here

read this: Read this before posting a programming question ... - Programming Questions - Arduino Forum

Things that you want to happen repeatably without input(pushing the button) need to go in void loop().

the delay() function is going to give you trouble because nothing can happen during a delay

http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

these tutorials should help also:

Demonstration code for several things at the same time - Project Guidance - Arduino Forum

https://learn.adafruit.com/downloads/pdf/multi-tasking-the-arduino-part-1.pdf

Gammon Forum : Electronics : Microprocessors : Switches tutorial

.

Wow.

That actually a HUGE info for me Hutkikz .

Thank you so much