interrupts with pro micro

I cant get intterupts to dettach. Im using a pro micro as a HID device to trigger hotkeys for a computer program. I have two buttons, upon pressing button 1 a keystroke is sent, and pressing button 2 a different key stroke is sent.

button 1 is physically attached to pin 3, and button 2 is attached to pin 7

here is my code:

//defining key strokes
#define F5     0xC6
#define F6     0xC7


//setting digital pins
const int button1 = 3;
const int button2 = 7;

void setup()
{
  attachInterrupt(digitalPinToInterrupt(button1), taskone, LOW);
  attachInterrupt(digitalPinToInterrupt(button2), tasktwo, LOW);
}

void loop()
{

}

void taskone() //run when button1 is pressed
{

  disarm_buttons; //detach interrupts while running the following code

  Keyboard.write(F5); //send key stroke

  delay(1000); //prevents multiple "presses"

  arm_buttons; // reattach interrupts
 
}

void tasktwo() //run when button2 is pressed
{

  disarm_buttons; //detach interrupts while running the following code

  Keyboard.write(F6); //send key stroke

  delay(1000); //prevents multiple "presses"

  arm_buttons; //reattach interupts
 
}

void arm_buttons()
{
  attachInterrupt(digitalPinToInterrupt(button1), domark, LOW);
  attachInterrupt(digitalPinToInterrupt(button2), dotrack, LOW);
}

void disarm_buttons()
{
  detachInterrupt(button1);
  detachInterrupt(button2);
}

My problem is; with the delay in the ISRs the interrupt should only trigger once every 1000ms (one second), but when i press the button it fires rapidly no delay. I manipulated to code to see if the interrupts were detaching by removing the "arm_buttons" at the end of the ISRs, they don't seem to be.

am i missing something here?

Perhaps you could try this:

void disarm_buttons()
{
  detachInterrupt(digitalPinToInterrupt(button1));
  detachInterrupt(digitalPinToInterrupt(button2));
}

Also, are you sure you want to use LOW? Maybe FALLING would be a better choice.

Don't use interrupts to detect button presses unless you have extra special circumstances. Buttons pressed by humans are slow and can be processed by polling. If you are determined to use interrupts, then read Nick Gammon's excellent hints.

disarm_buttons; //detach interrupts while running the following code

That's not how you invoke a function.

arduarn:
Don't use interrupts to detect button presses unless you have extra special circumstances. Buttons pressed by humans are slow and can be processed by polling. If you are determined to use interrupts, then read Nick Gammon's excellent hints.

disarm_buttons; //detach interrupts while running the following code

That's not how you invoke a function.

what is the correct way?

disarm_buttons();

robbieaggas:
My problem is; with the delay in the ISRs

There should NEVER be a delay() in an ISR. Any ISR that takes more than 100µsecs to complete is too slow.

...R

delay() won't work in an ISR, even if it was advisable, since delay() relies on millis() to return the proper time, and millis() relies on the click tick interrupt handler firing regularly. While your ISR is running, the clock tick handler can't, so millis() always returns the same time, and delay() never ends, because time never passes.

thanks every one. after reading gammons article, I realized i was way off.

detachInterrupt(digitalPinToInterrupt(button1));

works best

i wasn't properly calling functions, and you cant use delays in ISRs... didnt know that

also running elaborate processes in an ISR is a poor idea

Are you sure you can attach to an external interrupt on pin 7? I'm not familiar with Pro Micros, but the pinout diagrams I have seen don't have that as an option.

Jimmus:
Are you sure you can attach to an external interrupt on pin 7? I'm not familiar with Pro Micros, but the pinout diagrams I have seen don't have that as an option.

From the schematic here, pin 7 corresponds with PE6 (port E 6) which, according to the ATMega32U4 datasheet, has the external interrupt capability:

INT6/AIN0 – Port E, Bit 6
INT6, External Interrupt source 6: The PE6 pin can serve as an external interrupt source.