unsigned long newMillis = 0, oldMillis = 0; // 1. event time keepers
unsigned long interval = 500; // 2. LED blink rate in milliseconds
bool state; // 3. the state of the LED
byte buttonPin = 2; // 4, button pin
void setup() {
Serial.begin(115200); // 1. configure Serial Monitor baud
pinMode(LED_BUILTIN, OUTPUT); // 2. configure LED_BUILTIN/DIO pin 13 as OUTPUT
pinMode(buttonPin, INPUT_PULLUP); // 3. configure button pin as INPUT with internal pullup resistor
}
void loop() {
blink(); // 1. call the "blink" function
pause(); // 2. call the "pause button" function
}
void blink() {
newMillis = millis(); // 1. start an event
if (newMillis - oldMillis > interval) { // 2. compare difference in event times to interval
oldMillis = newMillis; // 3. store the new event start time
state = !state; // 4. flip the current state for the LED
digitalWrite(LED_BUILTIN, state); // 5. set the LED to the current state
if (state) Serial.print("1"); // 6. show current state if HIGH in Serial Monitor
else Serial.print("0"); // 7. show current state if LOW in Serial Monitor
}
}
void pause() {
while (!digitalRead(buttonPin)) {} // 1. hold here while button is being pressed
}pause
(hold)