#define SW1 4
#define SW2 16
int KeyPressesSW1 = 0;
bool statusSW1 = false;
int KeyPressesSW2 = 0;
bool statusSW2 = false;
void IRAM_ATTR isrSW1() {
KeyPressesSW1 += 1;
statusSW1 = true;
}
void IRAM_ATTR isrSW2() {
KeyPressesSW2 += 1;
statusSW2 = true;
}
void setup() {
Serial.begin(115200);
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
attachInterrupt(SW1, isrSW1, RISING);
attachInterrupt(SW2, isrSW2, RISING);
}
void loop() {
if (statusSW1) {
Serial.printf("SW1 press %u times\n", KeyPressesSW1);
statusSW1 = false;
}
if (statusSW2) {
Serial.printf("SW2 press %u times\n", KeyPressesSW2);
statusSW2 = false;
}
}