using multiple pin change interrupts

hehe, sorry for my bad English :slight_smile:

here is my full code, hopefully you can send me in the right direction

#include "MonsterMoto.h"

//PIN's definition
#define encoder1PinA  2
#define encoder1PinB  3

#define encoder2PinA  10
#define encoder2PinB  11

volatile int encoder1Pos = 0;
volatile boolean Past1A = 0;
volatile boolean Past1B = 0;

volatile int encoder2Pos = 0;
volatile boolean Past2A = 0;
volatile boolean Past2B = 0;

MonsterMoto drive ;

ISR(PCINT2_vect)
{
  // interrupt on pin 10
  doEncoder2A() ;
}

ISR(PCINT3_vect)
{
  // interrupt on pin 11
  doEncoder2B() ;
}

void setup() 
{
  Serial.begin(115200) ;
  
  pinMode(encoder1PinA, INPUT);
  pinMode(encoder1PinB, INPUT); 
  
  pinMode(encoder2PinA, INPUT);
  pinMode(encoder2PinB, INPUT);
  
  Past1A = (boolean)digitalRead(encoder1PinA); //initial value of channel A;
  Past1B = (boolean)digitalRead(encoder1PinB); //and channel B

  Past2A = (boolean)digitalRead(encoder2PinA); //initial value of channel A;
  Past2B = (boolean)digitalRead(encoder2PinB); //and channel B

//To speed up even more, you may define manually the ISRs
// encoder A channel on interrupt 0 (Arduino's pin 2)
  attachInterrupt(0, doEncoder1A, RISING);
// encoder B channel pin on interrupt 1 (Arduino's pin 3)
  attachInterrupt(1, doEncoder1B, CHANGE); 

  // pin change interrupt
  PCMSK1 |= bit (PCINT2) ;  // we want pin 10
  PCMSK1 |= bit (PCINT3) ;  // we want pin 11
  PCIFR |= bit (PCIF0) ;    // clear any outstanding interrupts
  PCICR |= bit (PCIE0) ;    // enable pin change interrupts for D8 to D13
  
  //attachInterrupt(digitalPinToInterrupt(encoder2PinA), doEncoder2A, RISING) ;
  //attachInterrupt(digitalPinToInterrupt(encoder2PinB), doEncoder2B, CHANGE) ;
}


void loop()
{  
 //your stuff....ENJOY! :D
 //drive.motorGo(0, CCW, 125) ;

 Serial.print("encoder 1 : ") ;
 Serial.print(encoder1Pos) ;
 Serial.print("\n") ;
 
 Serial.print("encoder 2 : ") ;
 Serial.print(encoder2Pos) ;
 Serial.print("\n") ;
}

//you may easily modify the code get quadrature..
//..but be sure this wouldn't let Arduino back! 
void doEncoder1A()
{
     Past1B ? encoder1Pos--:  encoder1Pos++;
}

void doEncoder1B()
{
     Past1B = !Past1B; 
}

void doEncoder2A()
{
     Past2B ? encoder2Pos--:  encoder2Pos++;
}

void doEncoder2B()
{
     Past2B = !Past2B; 
}