I am not always printing the message “switch open interrupt!” when I open a closed switch.
I use D6 and set it high and connect to D7 via a digital closed switch. With this setup the D7 blue led is on, but getting strange results when opening switch multiple times. Is this a correct setup to monitor a closed switch and generate an interrupt when it goes open?
int switch = D7;
int sethigh3v = D6;
void setup() {
Serial.begin(9600);
pinMode(sethigh3v, OUTPUT);
digitalWrite(sethigh3v, HIGH);
pinMode(switch, INPUT_PULLDOWN);
attachInterrupt(switch, isrEvent, FALLING);
}
void loop() {
//check digital switch
checkEvents();
}
void isrEvent() {
if (digitalRead(button)==HIGH && systemHasNoticed == false) {
systemHasNoticed = true;
}
}
void checkEvents() {
if(digitalRead(button)==HIGH && systemHasNoticed == true) {
Serial.println("switch open interrupt!");
systemHasNoticed = false;
}
}