#define RUN 2
#define MODE 33
#define DEBOUNCE_TIME 200
void IRAM_ATTR modeISR();
volatile int mode = 0;
volatile bool modeChanged = false;
volatile unsigned long prev_press = millis();
//----------------------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(57600);
pinMode(RUN, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
attachInterrupt(12, modeISR, RISING);
attachInterrupt(13, modeISR, RISING);
attachInterrupt(14, modeISR, RISING);
attachInterrupt(25, modeISR, RISING);
attachInterrupt(26, modeISR, RISING);
Serial.println("Welcome");
}
//----------------------------------------------------------------------------------------------------------------------
void loop()
{
if (digitalRead(RUN) == LOW)
Serial.print('~');
if (modeChanged) {
modeChanged = false;
Serial.print(mode);
}
delay(100);
}
void IRAM_ATTR modeISR()
{
if (millis() - prev_press < DEBOUNCE_TIME)
return;
prev_press = millis();
mode++;
modeChanged = true;
}