I'm new to Arduino and trying to figure out my nano esp 32.
I have the following sketch from the examples/esp32/GPO/FunctionalInterrupt.ino
#include <Arduino.h>
#include <FunctionalInterrupt.h>
#define BUTTON1 17
#define BUTTON2 18
class Button{
public:
Button(uint8_t reqPin) : PIN(reqPin){
pinMode(PIN, INPUT_PULLUP);
};
void begin(){
attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING);
Serial.printf("Started button interrupt on pin %d\n", PIN);
}
~Button(){
detachInterrupt(PIN);
}
void ARDUINO_ISR_ATTR isr(){
numberKeyPresses += 1;
pressed = true;
}
void checkPressed(){
if (pressed) {
Serial.printf("Button on pin %u has been pressed %u times\n", PIN, numberKeyPresses);
pressed = false;
}
}
private:
const uint8_t PIN;
volatile uint32_t numberKeyPresses;
volatile bool pressed;
};
Button button1(BUTTON1);
Button button2(BUTTON2);
void setup() {
Serial.begin(9600);
while(!Serial) delay(10);
Serial.println("Starting Functional Interrupt example.");
button1.begin();
button2.begin();
Serial.println("Setup done.");
}
void loop() {
button1.checkPressed();
button2.checkPressed();
}
The comments in the sketch (omitted here for brevity) say to place a pushbutton between the pin and ground.
I run the sketch and see the initialization messages on the serial console, but no matter which pin I ground, the interrupts are not triggered.
I have tried both pin numbering schemes in the IDE, and have tried changing the BUTTON1 and BUTTON2 constants, but to no avail.
It's not obvious to me what might be wrong and I was hoping someone might point out my error.
Any help you may be able to offer would be gratefully received.
Many thanks.
Mike