#define SW1 13
#define SW2 12
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);
pinMode(SW2, INPUT);
attachInterrupt(SW1, isrSW1, CHANGE);
attachInterrupt(SW2, isrSW2, CHANGE);
}
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;
}
}