Hi!! I am new to the Arduino world and I have been trying to run the Interrupt's example on my Arduino DUE, but I just can't get it to work because my LED is always in the HIGH state.
This is my code:
int out = 9;
volatile int state = LOW;
volatile int count = 0;
void setup() {
// put your setup code here, to run once:
pinMode(out, OUTPUT);
// Init serial port
Serial.begin(9600);
// Attach interrupt on led change
attachInterrupt(out, toggle, CHANGE);
}
void loop() {
// write state to LED
digitalWriteDirect(out, state);
// print state and count
delay(2000);
Serial.println(state);
Serial.println(count);
}
void toggle() {
count++;
state = !state;
}
inline void digitalWriteDirect(int pin, boolean val){
if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
else g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}
I added a "count" variable to see whats happening and it is always printed as 1 so it seemed obvious that my interrupt was being triggered only once, so after some Googling I found this one year old bug that suggests to change "digitalWrite" to "digitalWriteDirect" to avoid this exact behaviour, but it's still not working.
Any ideas? I am using an Arduino DUE and 1.5.8 IDE running on OSX Mavericks.