train of lights, controlling speed

Hey everyone, I'm working on this arduino project and the instructions are below: "Create a train of lights that moves in reaction to a 90 second red/green cycle. Somewhere on your board should be a traffic light, with a green, yellow, and red light. When the light is green, the train of lights should move at some pace. When the light is yellow, the train should slow down. It should stop when the light is red (you must have a light stopped in the LED train when the light turns reD)."

Now what I was going to do for the breadboard part of this is have 5 led's for the train and an RGB LED wired for the red, green, yellow part of the project.

What really confuses me right now is the coding part of the project. What I was going to do is create a function for the green cycle, a function for the yellow cycle, and for the red part just do something in the void loop like digitalWrite(10,HIGH) or whatever. What I get stuck on is keeping the loop going for 30 seconds. What I did was (say I made a function named Green() for the green section of the train and one named yellow for the yellow section):

void loop () { digitalWrite(greenled, HIGH); green() delay(30000) digitalWrite(yellowled, HIGH); yellow() delay(30000) blahblahblah

Unfortunately this script just has the green train run once instead of running continuously for 30seconds. How can I stop this from happening? Keep in mind my knowledge of arduino is really beginner-ey and I don't know many different commands.

Always attach your full sketch using the icon.

Never use delay()

Read and master the sketch "blink without delay" that comes with a the the IDE.

Thanks for the reply! Will do from now on.

Will using "blinking without delay" eliminate my problem of the function not repeating?

EDIT: I read this (http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay). But am still very confused as to how blinking without delay works. How exactly would I implement this into my code?

//initialization unsigned long greentime greentime = 0

if (millis() - greenTime < 30000 ) green()

if ( mills() - greenTime > 30000)and (mills() - greenTime < 60000) yellow()

if mills() - greenTime > 60000 ) and ( millis() - greenTime < 90000) red ()

if (millis() - greenTime > 90000) greenTime=0

dave-in-nj: //initialization unsigned long greentime greentime = 0

if (millis() - greenTime < 30000 ) green()

if ( mills() - greenTime > 30000)and (mills() - greenTime < 60000) yellow()

if mills() - greenTime > 60000 ) and ( millis() - greenTime < 90000) red ()

if (millis() - greenTime > 90000) greenTime=0

WOW, thanks so much! Understand it now! So what exactly does "unsigned long" do? I saw it in the tutorial as well but I've only worked with "int x" or something like that.

unsigned long says its a positive number from 0 to 2^32.
millis() and micros() both return unsigned long numbers.
int are signed 16 bit numbers, -2^15 to 2^15
unsigned int would be positive numbers, 0 to 2^16.

policeboy0: WOW, thanks so much! Understand it now! So what exactly does "unsigned long" do? I saw it in the tutorial as well but I've only worked with "int x" or something like that.

i posted the idea, you have to edit it

need to add ; and { properly.