Is there a reasonably easy way to create an event driven button press? I am using ESP-WROOM-32 ESP32 ESP-32S WiFi + Bluetooth Dev Board and Arduino IDE. I know that the loop speed is really fast but I’m planning on having the project do some other tasks while it’s waiting for the button to be pushed. Think of it as a slap button response (so the button will be pressed very momentarily). Below is a simple example of my current code … I’d like to replace the recursive loop with an event driven version so that with everything else going on, it won’t run the risk of missing a really quick button slap.
// BUTTON SENSING INPUT
const int btnInputPin1 = 12;
// BUTTON LED OUTPUT
const int ledOutputPin1 = 25;
// BUTTON LED STATUS
bool ledStatus1 = false;
void setup() {
// Set LED pin to output
pinMode(ledOutputPin1, OUTPUT);
// Set BUTTON pin to input
pinMode(btnInputPin1, INPUT);
// Initially turn OFF all LEDs
digitalWrite(ledOutputPin1, HIGH);
ledStatus1 = true;
}
void loop() {
if ((digitalRead(btnInputPin1) == HIGH) && (ledStatus1 == true)) {
digitalWrite(ledOutputPin1, LOW);
ledStatus1 = false;
}
}