I have been trying to combine a few different basic codes to achieve a switch/case style code where each case loops (an LED pattern) and a momentary push button can break the loop and move to the next case (which will loops a different LED pattern).
Im not sure if switch/case is right for this, any advice or sample codes similar to what I'm after? My searches have all run dry
Basic concept:
check for button
run LED loop 1 (looped)
check for button
run LED loop 2 (looped)
check for button
run LED loop 3 (looped)
MatthewUser:
I have been trying to combine a few different basic codes to achieve a switch/case style code where each case loops (an LED pattern) and a momentary push button can break the loop and move to the next case (which will loops a different LED pattern).
Im not sure if switch/case is right for this, any advice or sample codes similar to what I'm after? My searches have all run dry
Basic concept:
check for button
run LED loop 1 (looped)
check for button
run LED loop 2 (looped)
check for button
run LED loop 3 (looped)
And your loop code might look something like this:
void loop()
{
switch (patternState)
{
case pattern1:
while (!isButtonPressed());
//Code to flash LED in pattern 1;
break;
case pattern2:
while (!isButtonPressed());
//Code to flash LED in pattern 2;
break;
case pattern3:
while (!isButtonPressed());
//Code to flash LED in pattern 3;
break;
}
Since each pattern has a while loop, it needs a check inside the loop to see if the button was pressed.
Is much more simple if you implement this in the "BlinkWithoutDelay" fashion. If you push the button you increment the "pattern" variable and you reset the "step" (of the pattern) variable.
You have been asked to post some code, and you have been told that your question is too vague... You didn't post code or explained what you want to do, so no one can help you...