# define CHECK_INTERVAL 50
# define startStopPin 7
# define runningLED 6
# define qPin 5
void setup() {
Serial.begin(115200);
Serial.println("HelloWorld!\n");
pinMode(startStopPin, INPUT_PULLUP);
pinMode(runningLED, OUTPUT);
}
unsigned long tmrCheck;
bool startStopStatus;
bool previousState = HIGH;
bool running;
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - tmrCheck > CHECK_INTERVAL) {
startStopStatus = digitalRead(startStopPin);
if (startStopStatus != previousState) {
if (previousState == HIGH)
running = !running;
else
digitalWrite(qPin, !digitalRead(qPin));
tmrCheck = currentMillis;
previousState = startStopStatus;
}
}
digitalWrite(runningLED, running);
}
void loopX() {
unsigned long currentMillis = millis();
if (currentMillis - tmrCheck >= CHECK_INTERVAL) {
// It's time to check the Start/Stop button!
startStopStatus = digitalRead(startStopPin);
// Changed? Toggle the "Running" state
if (startStopStatus != previousState) running = !running;
// Next check
tmrCheck = currentMillis;
previousState = startStopStatus;
}
digitalWrite(runningLED, running);
}