External interrupts not working

I have a nano 2040 connect and trying to get the external interupts to work. My first attempt in VSC generated an error error: 'led_ISR' was not declared in this scope for the line attachInterrupt(digitalPinToInterrupt(button), led_ISR, CHANGE); with led_ISR being underlined.

Then using the Arduino IDE and MBED core the code generates no errors but does nothing, the code is below. I have tried replacing button for 16 in the ISR setup, CHANGE for LEVEL but nothing works.

Does any one know if external pin ISR's are implemented for the 2040 connect?

For VSC, this used to have MBED as an option but now only shows the Arduino platform, so I am assuming this is the issue in VSC.

If I rem out the attachInterrupt line, and then setting the int led_state HIGH or LOW, the state of the led chnages and works OK.

I have also tried Earle Philhower board and this makes no difference.

#define led 14 // led as pin 14
#define button 16 // input for IRQ in pin 16
int led_state = LOW; // high / low state of led

void setup() {
pinMode(led, OUTPUT); // Led as output on pin 14
pinMode(button, INPUT_PULLUP); // input on pin 16, pulled high
attachInterrupt(digitalPinToInterrupt(button), led_ISR, CHANGE);
}

void led_ISR(){
led_state = !led_state;
}

void loop(){
digitalWrite(led, led_state);
}

Typically pin change interrupts are a feature of the microcontroller. As such there's no way in hardware to disable them.

Ah, BASIC...:wink:

Why would you keep writing that digitalPin if most of the time nothing changes anyway? Anyway, not the source of your problem, just somewhat odd.

How have you wired your button, and does your button read OK if you just poll it?

When the interrupt pin is pulled low nothing happens, under all conditions for setting the pin and interrupt. When the interrupt pin is pulled high it does work OK, code is below. The reason for continually writing to the LED pin is just to have visual indication when the interrupts are working.

#define led 14 // led as pin 14
#define button 17 // input for IRQ in pin 16
int led_state = HIGH; // high / low state of led

void setup() {
pinMode(led, OUTPUT); // Led as output on pin 14
pinMode(button, INPUT_PULLUP); // input on pin 16, pulled high
attachInterrupt(digitalPinToInterrupt(button), led_INT, LOW);
}

void led_INT(){
led_state = !led_state;
}

void loop(){
digitalWrite(led, led_state);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.