/*
Forum: https://forum.arduino.cc/t/esp32-button-library-using-multiple-button-s/1232693/15
Wokwi: https://wokwi.com/projects/391903073780043777
*/
#include <Arduino.h>
#include "Button.h"
const gpio_num_t buttonPin[] = {
GPIO_NUM_4, // 0
GPIO_NUM_5, // 1
GPIO_NUM_12, // 2
GPIO_NUM_13, // 3
GPIO_NUM_14, // 4
GPIO_NUM_15, // 5
GPIO_NUM_32, // 6
GPIO_NUM_18, // 7
GPIO_NUM_19, // 8
GPIO_NUM_33 // 9
};
const int NoOfButtons = sizeof(buttonPin)/sizeof(buttonPin[0]);
Button * btn[NoOfButtons];
int btnNo[NoOfButtons];
void onButtonPressDownCb(void *btn, void *usr_data) {
Serial.print("Button ");
Serial.print(*(int*)usr_data);
Serial.println(" pressed");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
for (int i = 0; i < NoOfButtons; i++) {
btnNo[i] = i;
btn[i] = new Button(buttonPin[i], false);
btn[i]->attachPressDownEventCb(&onButtonPressDownCb, &btnNo[i]);
}
}
void loop() {
}