i want to have it be able to transit between 3 modes: flashing, on, and off. so far, im able to switch between 2 of above mentioned modes, but i cant seem to get all 3 in. here is my code so far. any help is appreciated. thanks in advance.
Create a counter variable. Increment it each time the switch changes from not pressed to pressed. When the counter gets to 3 reset it to 0. Your three states are 0, 1, 2. When counter == 0 enable whatever code you need for that state - like maybe lamp off? When counter == 1enable code for flashing, and so on.
im a middle school student so im kinda clueless on syntax and whatnot, where should this variable and its affiliated coding fit in the above mentioned code? thanks for your help and time.
Good for you for looking at whether there is a change in state in a switch !
Here is a start:
//was there a switch change in state ?
if (buttonState != lastButtonState)
{
//update to this new state
lastButtonState = buttonState;
//is the switch now pressed ?
if (buttonState == PUSHED)
{
counter++;
//don’t go over the maximum
if(counter > maximumCount)
{
counter = 0;
}
}
}
Hello
I love this school assignment and I hope the TO is able to find the hidden design trap.
This school assignment will be used for the local Arduino training.