Hello,
I am trying to program a project similar to a microwave, where the timer can be canceled at anytime by opening the door. I've figured using the attachInterrupt method is the best way of doing this. However, When I use the "CHANGE" mode of the attachInterrupt it only seems to register a single external input change from that pin.
For example, when I boot up the code and trigger the limit switch to signal a change, the program registers and prints "Door Closed" but any additional opening and closing of the door does not changed the statements. I've attached a simple version of what I'm dealing with.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
volatile int doorAction = 2;
volatile int doorState;
volatile int doorClosed;
int acvtivation = 0;
int completion = 0;
void setup() {
pinMode (doorAction, INPUT);
attachInterrupt(digitalPinToInterrupt(doorAction), ISR_doorAction, CHANGE);
lcd.begin(16,2);
}
void loop() {
if (doorClosed == true){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("door is closed!");
delay(100);
}
else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("door is open!");
delay(100);
}
}
void ISR_doorAction () {
if (digitalRead(doorAction == LOW)) {
doorClosed = true;
}
else {
doorClosed = false;
}
}