Question.3
What will be printed on the serial monitor after pressing the push button switch?
Code
#define buttonPin 2
uint32_t previousValue = 0;
void handleInterrupt() {
delay(100);
previousValue = millis();
delay(1000);
Serial.println(previousValue - millis());
}
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(buttonPin), handleInterrupt, FALLING);
}
void loop() {
// Controller does some important tasks.
}