PinChangeInt not compiling

Hi community! My first post to the forum! :slight_smile:

So I'm trying to use the PinChangeInt library as I want to try to read 7 encoders using the Mega 2560.
I will then send the encoder values through OSC with the Ethernet shield.

After reading the intros to rotary encoders (Arduino Playground - RotaryEncoders) I got my code working with plain attachInterrupt, but since I need more pins I'm trying it with the PinChangeInt library.

When compiling I get:

In file included from semi_working_with_PinChangeInt.cpp:1:
/Users/ifranco/Documents/Arduino/libraries/PinChangeInt/PinChangeInt.h: In constructor 'PCintPort::PCintPort(int, volatile uint8_t&)':
/Users/ifranco/Documents/Arduino/libraries/PinChangeInt/PinChangeInt.h:80: error: 'NULL' was not declared in this scope
/Users/ifranco/Documents/Arduino/libraries/PinChangeInt/PinChangeInt.h: In constructor 'PCintPort::PCintPin::PCintPin()':
/Users/ifranco/Documents/Arduino/libraries/PinChangeInt/PinChangeInt.h:93: error: 'NULL' was not declared in this scope

my sketch goes like this:

#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
#include <SPI.h>
#include <Ethernet.h> // version IDE 0022
#include <Z_OSC.h>

#define encoder0PinA 14
#define encoder0PinB 15

long int encoder0Pos = 0;

///////////////////////////////////////////////////////////////  
// SET THE RIGHT ADDRESS FOR ARDUINO 
///////////////////////////////////////////////////////////////
byte myMac[]= {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // TO SET ADDRESS MAC ARDUINO CARD
byte myIp[] = { 169, 254, 190, 11 };      // TO SET ADDRESS IP ARDUINO CARD  
byte destIp[] = {169, 254, 190, 56};      // TO SET ADDRESS IP COMPUTER
int  destPort = 10000;                  // TO SET SENDING PORT
///////////////////////////////////////////////////////////////  
///////////////////////////////////////////////////////////////  

char oscAdr[] = "/enc1";
Z_OSCClient client;


void setup(){
  
Ethernet.begin(myMac ,myIp);

pinMode(encoder0PinA, INPUT); 
pinMode(encoder0PinB, INPUT); 

digitalWrite(encoder0PinA, HIGH);
digitalWrite(encoder0PinB, HIGH);

//This is using plain interrupts
//// encoder pin on interrupt 0 (pin 2)
//attachInterrupt(0, doEncoderA, CHANGE);
//// encoder pin on interrupt 1 (pin 3)
//attachInterrupt(1, doEncoderB, CHANGE);  

//Now through the PinChangeInt library
 PCintPort::attachInterrupt(14, doEncoderA,CHANGE); 
 PCintPort::attachInterrupt(15, doEncoderB,CHANGE);

Serial.begin(19200);
  
}

void loop(){

Z_OSCMessage mes;  
  
mes.setAddress(destIp,destPort);
mes.setZ_OSCMessage(oscAdr ,"i" ,&encoder0Pos);
  
client.send(&mes);
  
mes.flush();  

Serial.print(encoder0Pos);
Serial.println();
  
delay(20);
  
}

void doEncoderA(){

  // look for a low-to-high on channel A
  if (digitalRead(encoder0PinA) == HIGH) { 

    // check channel B to see which way encoder is turning
    if (digitalRead(encoder0PinB) == LOW) {  
      encoder0Pos = encoder0Pos + 1;         // CW
    } 
    else {
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
  }

  else   // must be a high-to-low edge on channel A                                       
  { 
    // check channel B to see which way encoder is turning  
    if (digitalRead(encoder0PinB) == HIGH) {   
      encoder0Pos = encoder0Pos + 1;          // CW
    } 
    else {
      encoder0Pos = encoder0Pos - 1;          // CCW
    }
  }
//  Serial.println (encoder0Pos, DEC);          
  // use for debugging - remember to comment out

}

void doEncoderB(){

  // look for a low-to-high on channel B
  if (digitalRead(encoder0PinB) == HIGH) {   

   // check channel A to see which way encoder is turning
    if (digitalRead(encoder0PinA) == HIGH) {  
      encoder0Pos = encoder0Pos + 1;         // CW
    } 
    else {
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
  }

  // Look for a high-to-low on channel B

  else { 
    // check channel B to see which way encoder is turning  
    if (digitalRead(encoder0PinA) == LOW) {   
      encoder0Pos = encoder0Pos + 1;          // CW
    } 
    else {
      encoder0Pos = encoder0Pos - 1;          // CCW
    }
  }

}

Any help would be greatly appreciated!
Cheers all!
Ivan

A link to the PinChangeInt library would have been useful.

Of course, sorry!

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

It's suppose to help you with abstracting attach interrupts on any pin.

Howdy, that compile error is due to using an older version of PinChangeInt with a newer version of Arduino. Get the latest version at the google code group: Google Code Archive - Long-term storage for Google Code Project Hosting.

As to debugging your encoder code, try adding an LED between each leg of the encoder so you can verify the high/low behavior you are looking for.