// FROM: https://www.digikey.com/en/maker/tutorials/2022/how-to-use-arduino-interrupts-to-detect-user-inputs
#include <Arduino.h>
volatile bool execute = false;
void onDetectInterrupt(){
/* The Arduino calls this function when
it detects a falling edge on pin 2. */
execute = true;
}
void setup(){
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), onDetectInterrupt, FALLING);
Serial.begin(9600);
}
void loop()
{
/* Other code */
if(execute) {
// display sometinh when the interrpt happened
Serial.println("Hello world!");
// Don't forget to reset the flag
execute = false;
}
}