Interrupt not working on Leo

hi there I can not seem to get the Interrupt on pin 7 on the leo to work,I have this as a test code and it seems to work fine on pin 2 and 3, any ideas?

const byte LED = 13; const byte BUTTON = 7;

// Interrupt Service Routine (ISR) void pinChange () { if (digitalRead (BUTTON) == HIGH) digitalWrite (LED, HIGH); else digitalWrite (LED, LOW); } // end of pinChange

void setup () { pinMode (LED, OUTPUT); // so we can update the LED pinMode (BUTTON, INPUT); digitalWrite(BUTTON, HIGH); // turns the pullup on attachInterrupt (4, pinChange, CHANGE); // attach interrupt handler } // end of setup

void loop () { // loop doing nothing }

Which version of the IDE do you have? It looks to me like 1.0.3 does not implement attachInterrupt (4 ...) for the ATmega32U4 however 1.0.5 does.

Ah!

Mark

I am using 1.0.1 so that might be where my problem is I will have a go with 1.0.5

Hi Leo,

I have a same problem with UNO SMB R2
I tried to test with the reference’s example, and I hope the interrution is run several times.

The test is as follows :

int pin = 13;
volatile int state = LOW;

void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, RISING);
}

void loop()
{
digitalWrite(pin, state);
}

void blink()
{
state = !state;
}

The shema in file attach.

Schema.jpg

What problem do you have ? The program and schematic look OK to me, but each button press may produce several interrupts due to the contacts bouncing.

Hi UKHeliBob,

That's what I thought, but when i watching with osciloscope, I don't see the contacts bouncing. It Is possible to put a filter on the input to be sure there is no bounce? thank you

It Is possible to put a filter on the input to be sure there is no bounce?

Yes create a hardware debouncing circuit like this
This eliminate some spikes and the output is almost a perfect square wave