Button to start led blink sequence

Hi People.
I am new to programming and i am trying to make a board that (when pushed by a button)
starts a blinking sequence that looks like one that is used when there is a car-race. (red-red-red-green)
Now my question is how do i program the arduino so that if the button is pushed it starts the sequence 1 time?
i hope someone can help me.

Best regards , Pim

Hint:

if (digitalRead(button_pin)){

Do the sequence.

}

Leave your loop() function empty, like this:

void loop() {}

Here is some pseudocode. Put it in the setup() function.

do  { read input button } while input button is not pushed
turn red1 on
delay
turn red1 off
turn red2 on
delay
turn red2 off
turn red3 on
delay
turn red3 off
turn green on

aarg:

I believe he meant it runs once after hitting the button...not once during power cycle.

Johnny010:
I believe he meant it runs once after hitting the button...not once during power cycle.

That's what this does:

do  { read input button } while input button is not pushed

Sigh.

while (digitalRead(buttonSwitch) == HIGH) {}

for an active LOW button using INPUT_PULLUP

Ooops. I get it now.

That's what this does:

No, because you said:

Put it in the setup() function.

Once the (psuedo)code is done, setup() ends, and loop() does nothing. To get the switch to do something again, you need to reset the Arduino.

PaulS:
No, because you said:Once the (psuedo)code is done, setup() ends, and loop() does nothing. To get the switch to do something again, you need to reset the Arduino.

I know, but the OP didn't ask for that. In fact I was deliberately taking it literally,

so that if the button is pushed it starts the sequence 1 time?

It's my way of forcing people to think about what they ask for.

Also the light tree logic would be different for multiple cycles. The tree shouldn't pause at "green" for a new race. Instead, initially all the lights should go out or at least the top red should be on (I don't know, I don't follow NASCAR). But all this should be fleshed out by the OP as a design learning experience.

But all this should be fleshed out by the OP as a design learning experience.

Absolutely.

This is why we program in C, not english. People quibbling over ambiguities like:

"so that [if the button is pushed it starts the sequence] 1 time?"
or
"so that if the button is pushed [it starts the sequence 1 time]?"

But in answer to the OP's question:

The easy way is to use delay(). In the loop, if the button is down AND the button was up last time the loop was executed, then do the flash sequence. It might be a good idea to move the flash sequence into a separate function. This can make the logic of the button-detection code clearer.