need a push button activation

Hello,
I have a multiple timer (20 to be exact) running on a Mega and using 20 relays on two relay boards to control my high current loads.

I now wish to add a push button to start one of my timers but I don't know how or where to even look.

I have added the "light an LED with a button routine and tried my hand but didn't get too far.

I have included my code

Is there any way to clean the code up? It seems like a lot of repetition

Thanks

_20_slot_timer.ino (15.9 KB)

Delta_G

Thanks a million..

I will heed the advise and attempt to learn about using arrays.. This old brain of mine doesn't absorb like it used to..

Can you show me an example of using a push button to start one of the timers.. I hate asking but I really have no idea how to do it and I'm feeling pretty defeated with my futile attempts. I have looked at the button examples and I can light my LEDs but cant for the life of me figure out the timer issue..

Again Thanks

Pushbuttons are unaccountably nasty. The problem is called "contact bounce". The thing is a normal switch - light switch or anything - doesn't immediately make contact. It's a mechanical device which moves much more slowly than your Arduino program. An Arduino processor is fast enough to see the little tiny sparks jumping the gap in a few microseconds and then it thinks you've pressed the button 4 or 5 times.

Once you've got the contact bounce idea, then you can look at the different methods of "debouncing" and pick one that you understand and can apply to your program.

I can de bounce the button without a problem, I have done that in different sketches.. My issue is getting the button state change to start one of my timers in my sketch..

Do you want one of your outputs to be dormant and not blink unless the button is pressed? YES

I want one of the strings to not start until a push button is pressed, then stop at the end of the blinkDuration and wait for the button push before it starts again.. As it is now, all 20 start and continuously loop until power is shut off..

if(variable == false){
variable = digitalRead(button);
}
If (variable == true){
// run routine & timing code

    variable = false  //reset at end of routine
}