My problem is that I've been trying to take external interrupts from a button to change a variable in the program. I have tried everything, attachInterrupts(), volatiles, even tried with standard <avr/interrupt.h>. Please help! Because I was working in a bigger project and didn't want to confuse you guys with unrelated code, I modify a the Button sketch to insted use interrupts but still this simple example does not work.
...
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
volatile bool buttonState = false; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// digitalWrite(buttonPin, HIGH);
attachInterrupt(buttonPin,flash,LOW);
}
void loop(){
}
void flash()
{
if (buttonState == true) {
// turn LED on:
digitalWrite(ledPin, LOW);
buttonState = false;
}
else {
// turn LED off:
digitalWrite(ledPin, HIGH);
buttonState = true;
}
}