In the following code how do I get the SM running with a HIGH input to pin 8? It will run(blink) if I start it in state 2, But I can't seem to get it to start with the button push.
Thanks
Tom
[quote]
[color=#CC6600]int[/color] inPin = 8; [color=#7E7E7E]// pushbutton connected to digital pin 8[/color]
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
[color=#CC6600]pinMode[/color](13,[color=#006699]OUTPUT[/color]);
[color=#CC6600]pinMode[/color](inPin,[color=#006699]INPUT[/color]);
}
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
[color=#CC6600]static[/color] [color=#CC6600]int[/color] state = 1; [color=#7E7E7E]// initial state is 1, the "idle" state.[/color]
[color=#CC6600]static[/color] [color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] ts; [color=#7E7E7E]// To store the "current" time in for delays.[/color]
[color=#CC6600]switch[/color](state)
{
[color=#CC6600]case[/color] 1:
[color=#7E7E7E]//???[/color]
[color=#CC6600]break[/color];
[color=#CC6600]case[/color] 2:
[color=#CC6600]digitalWrite[/color](13,[color=#006699]HIGH[/color]); [color=#7E7E7E]// Turn on the light[/color]
ts = [color=#CC6600]millis[/color](); [color=#7E7E7E]// Remember the current time[/color]
state = 3; [color=#7E7E7E]// Move to the next state[/color]
[color=#CC6600]break[/color];
[color=#CC6600]case[/color] 3:
[color=#7E7E7E]// If one second has passed, then move on to the next state.[/color]
[color=#CC6600]if[/color]([color=#CC6600]millis[/color]() > ts + 1000)
{
state = 4;
}
[color=#CC6600]break[/color];
[color=#CC6600]case[/color] 4:
[color=#CC6600]digitalWrite[/color](13,[color=#006699]LOW[/color]); [color=#7E7E7E]// Turn off the light[/color]
ts = [color=#CC6600]millis[/color](); [color=#7E7E7E]// Remember the current time[/color]
state = 5;
[color=#CC6600]break[/color];
[color=#CC6600]case[/color] 5:
[color=#7E7E7E]// If one second has passed, then go back to state 2.[/color]
[color=#CC6600]if[/color]([color=#CC6600]millis[/color]() > ts + 1000)
{
state = 2;
}
[color=#CC6600]break[/color];
[color=#CC6600]case[/color] 6:
[color=#7E7E7E]// We only get here when forced from outside.[/color]
[color=#CC6600]digitalWrite[/color](13,[color=#006699]LOW[/color]); [color=#7E7E7E]// Turn off the light[/color]
state = 1; [color=#7E7E7E]// Return to the "idle" state.[/color]
[color=#CC6600]break[/color];
[color=#CC6600]default[/color]:
state = 1;
[color=#CC6600]break[/color];
}
}
[/quote]