Interrupts & Debounce

I have been using the Bounce library on another project and it works well.

I am now trying to use on for interrupts and I still am experiencing a severe bounce on pressing the push button.

Am I doing something wrong and can this library be used with interrupts ?

#include <Bounce.h>

#define INPUT1 2
#define INPUT2 3

int pin = 7;
int heart_led = 12;

volatile int state = LOW;

const int debounce = 1000;      // How long debounce we want before sending a new message about mail arrived (1000 = 1 seconds)

Bounce output1 = Bounce(INPUT1, 10);    //Initiate a Bounce object with a 5 millisecond debounce time
Bounce output2 = Bounce(INPUT2, 10);

long int timeout1;
long int timeout2;

boolean unfound1 = true;
boolean unfound2 = true;

void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(heart_led, OUTPUT);
  
  pinMode(INPUT1, INPUT);
  pinMode(INPUT2, INPUT);
  
  digitalWrite(INPUT1, HIGH); // pull up resistor
  digitalWrite(INPUT2, HIGH); // pull up resistor
  
  
  attachInterrupt(0, blink1, LOW);
  attachInterrupt(1, blink2, LOW);
  
  Serial.begin(9600); // send and receive at 9600 baud
}

void loop()
{
  digitalWrite(pin, state);
  output2.update ( );
  HeartBeat();
}

void HeartBeat()
{
  digitalWrite(heart_led, LOW);
  delay(2000);
  digitalWrite(heart_led, HIGH);
  delay(50);
}

void blink1()
{
  output1.update ( );              // Update the debouncer
  int value1 = output1.read();     // read the state of the pushbutton value:
  if ((millis() > timeout1 + debounce) && value1 == HIGH) unfound1 = true;

  // check if the pushbutton is pressed.
  if (value1 == LOW && unfound1) {
      Serial.println("Called interrupt1");
      state = !state;
      unfound1 = false;
      timeout1 = millis();
  }
}

void blink2()
{
  output2.update ( );              // Update the debouncer
  int value2 = output2.read();     // read the state of the pushbutton value:
  if ((millis() > timeout2 + debounce) && value2 == HIGH) unfound2 = true;
  
  // check if the pushbutton is pressed.
  if (value2 == LOW && unfound2) {
      Serial.println("Called interrupt2");
      state = !state;
      unfound2 = false;
      timeout2 = millis();
  }
}

attachInterrupt(1, blink2, LOW);

This interrupt handler will be called over and over again as long as the switch pin is LOW. This is not what an interrupt handler is designed for.

Why do you need to use interrupts for switches that are pressed by humans, anyway?

The code incorrect was posted incorrectly, so has been revised.

I have seen interrupts used for switched inputs all over this forum, so whos to say this is not what they can be used for.

The switch is to mimic an input from an alarm sensor whilst the code is in development as its easier to use the switch instead of the alarm sensor.

I thought an interrupt would be the best way forward for this application as no matter what the rest of the code is doing, as soon as a sensor is triggered, it reacts accordingly.

I have seen interrupts used for switched inputs all over this forum, so whos to say this is not what they can be used for.

I'm not saying you can't use an interrupt handler this way. You can. It just doesn't make sense to me. An interrupt is generally used for when things change. A phone rings, a doorbell chimes, and alarm goes off. You don't need to be constantly alerted to the fact that the phone is not ringing.

I am now trying to use on for interrupts and I still am experiencing a severe bounce on pressing the push button.

What does this mean? Is the interrupt handler called more than you think it should be?

Why have you got serial prints in an ISR?

  attachInterrupt(0, blink1, LOW);

As Paul pointed out, this blink1 routine will be called while the line is low. Possibly thousands of times. I wouldn't do it with LOW. Use FALLING or CHANGE.