Hello everybody,
I would like to use two interrups on the same pin. The first interrupts detects a falling edge on D2, the second one detects a falling edge. This doesn’t seem to work. Is this because you can’t use two interrupts on the same pin. If so, can this be solved?
The code can be seen below:
void blink1(void);
void blink2(void);
int ledPin = D7;
volatile int value=0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(D2, INPUT_PULLDOWN);
attachInterrupt(D2, blink1, FALLING);
attachInterrupt(D2, blink2, RISING);
Serial.begin(9600);
}
void loop()
{
if (value>0){
noInterrupts();
digitalWrite(ledPin, HIGH);
Serial.println("Object detected");
value=0;
delay(1000);
interrupts();
}
if (value<0){
noInterrupts();
digitalWrite(ledPin, LOW);
Serial.println("No object detected");
value=0;
delay(1000);
interrupts();
}
}
void blink1()
{
value--;
}
void blink2()
{
value++;
}
Thanks for the advice,
Bart