Newbie here. Code question.

I am very new to the ardrino world, this makes post number uno for me. anyways...
So I just got the ardrino today. The device works fine, and I have a lot to learn. But I'm also in a hurry to show it off to some school mates and to the rents so here is what I want to do.
Simple Traffic Light.
I set up the physical part with LEDs and current limiting resisters and what not, but can't figure out the program. I have three LEDs, a red, a blue (blue as a stand in for yellow) and a green, and a push button. Here is what I want to do.
I want the red light to come and remain on.
When the push button is pressed, I want the LEDs to behave just like a traffic light. After some time has passed (an eternity if your impatient behind the wheel like I am sometimes.) the red led goes out and the green led lights., then after a brief moment, the green led goes out and blue led will light for an even shorter period of time. Then it goes out, and the red led lights.
This process will not repeat unless the push button is pressed.
A simple program it must be, and after I get my feet wet with it, I may expand upon it. But for now, can someone with more expertise and experience show me a simple program that will do as I described? I know how to assign pins, inputs, outputs and what not, but not the rest of it. Or point me in the direction of one that exist already?
I did find one, but it had more than I'm looking for. Any help would be greatly appreciated.

To read the state of the switch:

int switchState = digitalRead(switchPin);

To do something based on the state of the switch:

if (switchState == HIGH)
{
  // code runs when pin is HIGH
}
else
{
  // code runs when pin is LOW
}

To turn an LED on:

digitalWrite(pin, HIGH);

To wait a certain amount of time:

delay(timeInMilliseconds);

To turn off an LED:

digitalWrite(pin, LOW);

Putting all this together to achieve what you are looking for is trivial.

Thanks for such a fast response. I will have to give these a go in the morning. :slight_smile:
So far, playing with the Blink example in the software, I couldn't figure out how to blink more than one led. In this case, three with the program. I could only change the time, and the output.
Thanks again.

NutsNCircuits:
Thanks for such a fast response. I will have to give these a go in the morning. :slight_smile:
So far, playing with the Blink example in the software, I couldn't figure out how to blink more than one led. In this case, three with the program. I could only change the time, and the output.
Thanks again.

If you're having trouble getting your code to do what you want, then you should be posting your code, lest you want general advice.

So far, playing with the Blink example in the software, I couldn't figure out how to blink more than one led.

Blinking three at the same rate is trivial. Blinking three at different rates is more complex. For that, you need to read, understand, and embrace the blink without delay example.

In fact, now, before you learn to like delay() is a good time to learn to not use delay(). It will cause you endless grief when you discover that you need to completely rewrite your sketch to fade three LEDs at different rates. With the knowledge that comes from embracing the blink without delay methodology, you'll never paint yourself into that corner.