Hi,
I’m attaching an interrupt to a port with a PIR sensor (see code below). But nothing happens when the PIR sensor is “activated” or “de-activated”. Removing pinMode(pir, INPUT_PULLUP); doesn’t change anything. What am I missing here?
indent preformatted text by 4 spaces
Thanks.
Guy
int pir = D0;
int blueLED = D1;
indent preformatted text by 4 spaces
void pirOn(void);
void pirOff(void);
volatile int state = LOW;
void setup() {
pinMode(pir, INPUT_PULLUP);
pinMode(blueLED, OUTPUT);
attachInterrupt(pir, pirOn, RISING);
attachInterrupt(pir, pirOff, FALLING);
}
void loop() {
// These statements work
/*if (digitalRead(pir) == HIGH) {
digitalWrite(blueLED, HIGH);
} else if (digitalRead(pir) == LOW) {
digitalWrite(blueLED, LOW);
}*/
digitalWrite(blueLED, state);
}
void pirOn() {
// Duplicate for testing
digitalWrite(blueLED, HIGH);
state = HIGH;
}
void pirOff() {
// Duplicate for testing
digitalWrite(blueLED, LOW);
state = LOW;
}