How do you use INT2 in Arduino sketches

An advanced Arduino-compatible board with ATmega1284P and ATmega32u2 MCUs for experienced users. More RAM than a Mega, but in a convenient Uno-style form factor. [Product page]
Post Reply
vicatcu
Posts: 7
Joined: Thu Aug 29, 2013 3:32 pm

How do you use INT2 in Arduino sketches

Post by vicatcu » Tue Oct 22, 2013 4:05 am

Has anyone figured out how to do attatchInterrupt for DIG8 (INT2) on Goldilocks yet?

feilipu
Posts: 52
Joined: Fri Jul 19, 2013 6:17 am

Re: How do you use INT2 in Arduino sketches

Post by feilipu » Wed Oct 23, 2013 2:57 am

Ok. I admit that I'm guessing, but from the Arduino Reference it looks as easy as defining the attached interrupt number 2:

Code: Select all

int pin = 13;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(2, blink, CHANGE);
}

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

void blink()
{
  state = !state;
}
Provided that Arduino codes behaves as expected, then it could work.

---

Except perhaps that, as usual, Arduino team like to complicate simple things.
The 32U4 (Leonardo) they seem to have numbered the Interrupts correctly because it was added later, but they renumbered the earlier 2560 (Mega) and when you think you are using Interrupt 0 you are actually using INT_4.

FFS What were they thinking?

But, anyway that doesn't affect the 1284p because it doesn't have the EICRB register.

Looking at the Arduino WInterrupts.c code in detail, it looks like the attachInterrupt() code could work, but the detachInterrupt() code will not, because they just couldn't be bothered to finish it...

Post Reply