Pausing an LED sequence using a pushbutton.

Hi everyone,

I have just started using Arduino and have currently built a little system to turn on a series of LEDs in sequence, with each getting brighter. This sequence is started with a pushbutton and then waits for the pushbutton before starting again.

Here is my code so far

void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(button, INPUT);
void loop(){
val = digitalRead(button);
if (val == HIGH) {
analogWrite(led1, 10);
analogWrite(led2, 30);
analogWrite(led3, 50);
analogWrite(led4, 75);
analogWrite(led5, 200);
analogWrite(led1, 0);
analogWrite(led2, 0);
analogWrite(led3, 0);
analogWrite(led4, 0);
analogWrite(led5, 0);
delay(1000); }

What I want to do now is to add another push button so that I can pause halfway through the sequence by pressing it and then I push the original button to continue the sequence where I left off. My problem is that I really have no idea where to start with getting the circuit to check for the 2nd button to pause during the sequence other than using IF statements in between every line. Would someone be able to point me in the right direction? I'm not looking for someone just to do it but I would just like a little direction to get started as I can't think of a way to do it.

Thanks very much in advance!

P.S. As a bonus question, is there anything I can do to neaten up the code I have? It looks like I'm doing a lot of the same thing but just with a different pin. Is it possible to, with the use of a FOR loop say, iterate so that I don't have all of these similar lines? Thanks.

Start by getting rid of all the delays. See blink without delay. Because the Arduino can't do anything else when a delay is happening.

And now the loop can run freely (no delays inside it) you can poll (check) the button in the loop and you're done ;)