Multi Ext Interrupt

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)

Cross posted in LEDs

It is impossible to answer your question or provide any insight without seeing the code and the wiring schematic.

Why are you using interrupts to read buttons?

Other thread removed.

Delta_G:
Cross posted in LEDs

Sorry, I newer.

Delta_G:
It is impossible to answer your question or provide any insight without seeing the code and the wiring schematic.

Why are you using interrupts to read buttons?

Yes.
Sometime is limit switch --> I using interrupts to stop motor.
Before I had used function Debouce_input_button() in loop(). But when esp on Reconnect() function then too late to response from input button.
With function Debouce_input_button() in loop() and both debouce by hardware and software but sometime I still noise: relay auto on/off while I not press any button!

void loop() 
{
 // Readbutton local
  realBt1State = debounce(BUTTON_1_PIN); 
  if (realBt1State != lastButton1Status) 
  {  
    relay1_local_reqed=1;
    lastButton1Status = realBt1State; 
    relay1_status = !relay1_status;
    aplyCmd();
  } 
   
  realBt2State = debounce(BUTTON_2_PIN);
  if (realBt2State != lastButton2Status) 
  {    
    relay2_local_reqed=1; 
    lastButton2Status = realBt2State; 
    relay2_status = !relay2_status;
    aplyCmd();
  }

  realBt3State = debounce(BUTTON_3_PIN);
  if (realBt3State != lastButton3Status) 
  {     
    relay3_local_reqed=1;
    lastButton3Status = realBt3State; 
    relay3_status = !relay3_status;
    aplyCmd();
  }

  realBt4State = debounce(BUTTON_4_PIN);
  if (realBt4State != lastButton4Status) 
  {     
    relay4_local_reqed=1;
    lastButton4Status = realBt4State; 
    relay4_status = !relay4_status;
    aplyCmd();
  } 
}
boolean debounce(int pin)
{
  boolean state;
  boolean previousState;
  const int debounceDelay = 5;

  previousState = digitalRead(pin);
  for (int counter = 0; counter < debounceDelay; counter++)
  {
    delay(1);
    state = digitalRead(pin);
    if (state != previousState)
    {
      counter = 0;
      previousState = state;
    }
  }
  return state;
}

I'm sorry.
Thanks

Hello Discovery88hl

Please post ALL your code.

Regards,
bidouilleelec

Delta_G:
It is impossible to answer your question or provide any insight without seeing the code and the wiring schematic.

Why are you using interrupts to read buttons?

All the code and the wiring.

You should check to see if there is one of the foreign language sections in your native tongue because you are very hard to understand.

I just do it.
Thanks everybody!