So basically I'm trying to create a device where when I push a button it starts a loop. When I push this button again, it stops the loop. Right now I have it logged to serial. It starts up correctly with no output. When I press the button the loop begins and it spits out "toggled on" continuously. When I press the button again... nothing happens. What should happen ideally is that it should stop spitting out "toggled on" and just go back to doing nothing.
#include <Bounce2.h>
Bounce bouncer = Bounce();
const int W = 10;
bool wOn = false;
void setup() {
Serial.begin(9600);
pinMode(W, INPUT_PULLUP);
bouncer.attach(W);
bouncer.interval(5);
}
void loop() {
bouncer.update();
if (bouncer.read() == LOW) {
wOn = !wOn;
}
if (wOn > 0) {
Serial.println("toggled on");
}
}