Wokwi simulates button bounce by default to more accurately model the real world, so it's advisable to have some form of button debouncing.
Wokwi simulates button bounce by default to more accurately model the real world, so it's advisable to have some form of button debouncing.
void loop ()
{
static bool doLightshow = false;
static Debouncer buttonOn(buttonON);
static Debouncer buttonOff(buttonOFF);
buttonOn.Update();
buttonOff.Update();
if (buttonOn.Fall())
{
Serial.println("buttonOn falling edge.");
doLightshow = true;
}
else if (buttonOff.Fall())
{
Serial.println("buttonOff falling edge.");
doLightshow = false;
}
if (doLightshow)
{
// Do lightshow.
. . .
}
else
{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
}
}
void loop ()
{
bool doLightshow = false;
static Debouncer buttonOn(buttonON);
static Debouncer buttonOff(buttonOFF);
buttonOn.Update();
buttonOff.Update();
if (buttonOn.Fall())
{
Serial.println("buttonOn falling edge.");
doLightshow = true;
}
else if (buttonOff.Fall())
{
Serial.println("buttonOff falling edge.");
doLightshow = false;
}
if (doLightshow)
{
// Do lightshow.
. . .
}
else
{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
}
}
void loop ()
{
static bool doLightshow = false;
static Debouncer buttonOn(buttonON);
static Debouncer buttonOff(buttonOFF);
buttonOn.Update();
buttonOff.Update();
if (buttonOn.Fall())
{
Serial.println("buttonOn falling edge.");
doLightshow = true;
}
else if (buttonOff.Fall())
{
Serial.println("buttonOff falling edge.");
doLightshow = false;
}
if (doLightshow)
{
// Do lightshow.
. . .
}
else
{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
}
}
lang-cpp