// Using a momentary switch to run different functions // each time it is pressed. // Variables int mySwitch = 0; int switchPin = 8; // Variables to track toggling of the switch int whichToggle = 1; int toggleFlag = 1; // Timer variables long timer = 0; int offset = 1000; // Setup void setup() { Serial.begin(9600); pinMode(switchPin, INPUT); timer = millis(); } // Das loop... void loop() { // Detect Switch mySwitch = digitalRead(switchPin); if(!mySwitch) { if (toggleFlag) { whichToggle = !whichToggle; toggleFlag = 0; } }else{ toggleFlag = 1; } // Timer if (timer + offset < millis()) { if(whichToggle) { doThingA(); }else{ doThingB(); } } } // Do Thing A void doThingA() { Serial.println("Doing thing A"); } // Do Thing B void doThingB() { Serial.println("Doing thing B"); }