I'm working with an arduino mega, and have setup a simple led flashing pattern from another example.
My question is the kit included a little push button.
What I would like to do is have multiple flash patterns uploaded to the arduino, and when the push button is pressed, tell it, ok, go from program 1, to program 2, program 3, program 4, etc. each time the button is pressed, then when you have cycled thru all the programs, it starts back at program 1.
Below is the code i'm using to flash 4 led's
int red = 12;
int blu = 11;
int wht1 = 10;
int wht2 = 9;
int redblue_time = 150;
int whtwht_time = 100;
long last_redblue = 0;
long last_whtwht = 0;
long time_now;
bool red_state = HIGH;
bool blue_state = LOW;
bool wht1_state = HIGH;
bool wht2_state = LOW;
// Red & Blue Lights
void setup()
{
pinMode(blu, OUTPUT);
pinMode(red, OUTPUT);
pinMode(wht1, OUTPUT);
pinMode(wht2, OUTPUT);
}
void loop()
{
time_now=millis();
if ((time_now - last_redblue) > redblue_time)
{
if (red_state == HIGH)
{
red_state=LOW;
blue_state=HIGH;
}
else
{
red_state=HIGH;
blue_state=LOW;
}
digitalWrite(red,red_state);
digitalWrite(blu,blue_state);
last_redblue=time_now;
}
if ((time_now - last_whtwht) > whtwht_time)
{
if (wht1_state == HIGH)
{
wht1_state=LOW;
wht2_state=HIGH;
}
else
{
wht1_state=HIGH;
wht2_state=LOW;
}
digitalWrite(wht1,wht1_state);
digitalWrite(wht2,wht2_state);
last_whtwht=time_now;
}
}
So how can i define when it detects button pressed, move on to another program (besides) the program already listed here.
Thanks