Hello,
I'm using an UNO R3 Plus and am trying to use a pin change interrupt for triggering an LED. Can you give me an idea of what I am doing wrong here? The LED isn't turning on, leading me to believe the interrupt isn't working. If I put the code from the interrupt into loop(), it works.
const int buttonPin = 5; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
boolean playMode = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
cli(); // disable global interrupts
PCMSK0 |= 1<<PCINT5;
PCICR |= 1<<PCIE0;
sei();
}
//Interrupt Service Routine (ISR)
ISR(PCINT0_vect) {
checkMode();
}
void checkMode() {
playMode = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (playMode == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
void loop(){
}
Thanks