Guest User

Untitled

a guest
Jan 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. volatile bool running = false;
  2. const uint8_t switch1 =3;
  3. const uint8_t switch2 =2;
  4.  
  5. void setup() {
  6. pinMode(switch1, INPUT_PULLUP);
  7. pinMode(switch2, INPUT_PULLUP);
  8. attachInterrupt(digitalPinToInterrupt(switch1), turnOn, FALLING);
  9. attachInterrupt(digitalPinToInterrupt(switch2), turnOff, FALLING);
  10. }
  11.  
  12. void loop() {
  13. if (running) {
  14. // Do something
  15. } else {
  16. // Do something else
  17. }
  18. }
  19.  
  20. void turnOn() {
  21. running = true;
  22. }
  23.  
  24. void turnOff() {
  25. running = false;
  26. }
Add Comment
Please, Sign In to add comment