reconfigure external interupt

Hello and thank you for looking at my post.

My project requires two separate External interrupts, unfortunately the interrupts are only available on pins 2 and 3 (arduino pro 5v). I’m using all six of the PWM pins 3,5,6… and … 9,10,11.

I’d really like to reconfigure pin 4 to be my second interrupt, so as not to use up the needed PWM pin 3.

I found this great site… https://sites.google.com/site/qeewiki/b … -atmega328 …that talks about reconfiguring external interrupts and it seems doable, unfortunately I’m not familiar enough with this low level chip stuff to really understand if what i’d like to do is possible, and how to do it.

I’d really appreciate if someone could modify the code below (from the the site) to make the reconfiguration in practical terms that i can understand. It sure would be enlightening as i’ve poured over the examples and can’t quite grock whats happening.

#include <avr/io.h>
#include <avr/interrupt.h>    // Needed to use interrupts    


int main(void)
{
    DDRB &= ~(1 << DDB0);         // Clear the PB0 pin
    // PB0 (PCINT0 pin) is now an input

    PORTB |= (1 << PORTB0);        // turn On the Pull-up
    // PB0 is now an input with pull-up enabled

    PCICR |= (1 << PCIE0);     // set PCIE0 to enable PCMSK0 scan
    PCMSK0 |= (1 << PCINT0);   // set PCINT0 to trigger an interrupt on state change 

    sei();                     // turn on interrupts

    while(1)
    {
        /*main program loop here */
    }
}



ISR (PCINT0_vect)
{
    if( (PINB & (1 << PINB0)) == 1 )
    {
        /* LOW to HIGH pin change */
    }
    else
    {
        /* HIGH to LOW pin change */
    }
}

… also, it would be great if this could be put in context of how it would integrate into the more familiar c/c++ arduino code i’m familiar with. such as the following from the example found here http://arduino.cc/en/Reference/attachInterrupt

int pin = 13;
volatile int state = LOW;

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

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

void blink()
{
  state = !state;
}

If you could help me with this my project will be a success. I’ve come a long long way to hit this troublesome crux.

Many thanks in advance,

G

(arduino pro 5v)

Mini I assume, not a Pro Micro. Try this library.

http://playground.arduino.cc/Main/PinChangeInt

Great! thank you.

I had looked at this library earlier in my search for a solution but didn’t invest enough time. Thanks for the nudge. It works :slight_smile: