Hi everybody,
I have some problem with multi ext interrupt on esp8266.
I have 4 button as ext interrupt input with both hardware debouce and software debouce. If only one interrupt used then OK. But when atachInterrupt all (4) button as ext interrupt input, it work not correct. Sometime I press button_1 but program jump to button_2(or 3 or 4)_interrupt.
Sorry I'll update code soon!
Thanks!
static unsigned long last_interrupt_time=0;
unsigned long interrupt_time = millis();
void disable_interrupt()
{
detachInterrupt(BUTTON_1_PIN);
detachInterrupt(BUTTON_2_PIN);
detachInterrupt(BUTTON_3_PIN);
detachInterrupt(BUTTON_4_PIN);
}
void enable_interrupt()
{
attachInterrupt(digitalPinToInterrupt(BUTTON_1_PIN), bt1_change, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_2_PIN), bt2_change, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_3_PIN), bt3_change, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_4_PIN), bt4_change, CHANGE);
}
void bt1_change()
{
disable_interrupt();
interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{
last_interrupt_time = interrupt_time;
relay1_local_reqed=1;
relay1_status = !relay1_status;
aplyCmd();
}
last_interrupt_time = interrupt_time;
enable_interrupt();
}
void bt2_change()
{
disable_interrupt();
interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{
last_interrupt_time = interrupt_time;
relay2_local_reqed=1;
relay2_status = !relay2_status;
aplyCmd();
}
last_interrupt_time = interrupt_time;
enable_interrupt();
}
void bt3_change()
{
disable_interrupt();
interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{
last_interrupt_time = interrupt_time;
relay3_local_reqed=1;
relay3_status = !relay3_status;
aplyCmd();
}
last_interrupt_time = interrupt_time;
enable_interrupt();
}
void bt4_change()
{
disable_interrupt();
interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{
last_interrupt_time = interrupt_time;
relay4_local_reqed=1;
relay4_status = !relay4_status;
aplyCmd();
}
last_interrupt_time = interrupt_time;
enable_interrupt();
}
void setup()
{
pinMode(BUTTON_1_PIN, INPUT);
pinMode(BUTTON_2_PIN, INPUT);
pinMode(BUTTON_3_PIN, INPUT);
pinMode(BUTTON_4_PIN, INPUT);
enable_interrupt();
}
void loop()
{
}
code.txt (2.46 KB)