I have a rotary encoder and I want to use the switch to stop the rest of my code running, essentially switching off what I have going on.
I have this
boolean running = true;
void setup() {
pinMode(swPin, INPUT);
digitalWrite(swPin, HIGH);;
}
void loop() {
if(digitalRead(swPin) == LOW) {
running = !running;
}
if(running) {
...
}
}
When I enter the if statement catching the switch press running does become false and the rest of the code is stopped. However, once releasedreleased; running is becoming true again and the rest starts again.
I guess it is because the rotary encoder isn't fixed in the LOW state but I expected the running variable to be set to false and remain since it is declared outside of the loop().
Any guidance would be much appreciated!!