I simply connected an LED + resistor on digital port D5 and I was trying to make it blink when I receive an interrupt on another pin.
Here the code:
const int ch0 = D5;
const byte interruptPin1 = D1;
const int triggertime = 1000;
int triggers = 0;
void sendPulse(int chan){
digitalWrite ( chan, HIGH );
delay (triggertime);
digitalWrite ( chan, LOW );
triggers ++;
Serial.print("Got trigger ");
Serial.println(triggers);
}
void handleInterrupt() {
Serial.println("Got interrupt 1");
sendPulse(ch0);
}
void setup() {
pinMode ( ch0, OUTPUT );
digitalWrite ( ch0, LOW );
Serial.begin ( 115200 );
pinMode(interruptPin1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin1), handleInterrupt, FALLING);
}
void loop() {
}
I attached a button to digital pin D1 and I would like to see the LED turn on for 1 second when the button is pressed.
I don't actually care of how many interrupts get triggered: I only want that when the button is pressed the LED gets powered for 1 second.
Everything works fine for a few clicks, then the LED does not turn on any longer when I press the key, while on the serial monitor I still see that the code is fully executed (interrupts detected and handlers processed).
What am I doing wrong?