Processing VSync.h

I have a program reading a rotary encoder attached to interrupts 0 and 1. Also I am using vsynch library to sync variables with a pc using processing. In processing I have a button in processing which I would like to reset the counts on the interrupt to zero. Is this even possible to restart encoder at zero again? Attached is part of the code I think is associated with the question.

#include <VSync.h>
//  Create a new sender here
//  Put the number of variables you want to sync in the pointy brackets
ValueSender<32> sender;
//  Create a new receiver here
//  It can receive up to two values
ValueReceiver<32> receiver;
/////variable declaration section..............................
void setup()
{
  //  You need to call Serial.begin() in order for value syncing to work.
  //  Make sure to use the same baudrate on both ends. More baud = more speed
  attachInterrupt(0, A_RISE, RISING);
  attachInterrupt(1, B_RISE, RISING);
  Serial.begin(115200);

  //  Tell the sender what variables to observe and keep in sync.
  //  Be sure to keep the order of variables the same on the receiving and the sending end!


}

void A_RISE(){
 detachInterrupt(0);
 A_SIG=1;
 
 if(B_SIG==0)
 pulses++;//moving forward
 if(B_SIG==1)
 pulses--;//moving reverse
//  Serial.println(pulses);
 attachInterrupt(0, A_FALL, FALLING);
}

void A_FALL(){
  detachInterrupt(0);
 A_SIG=0;
 
 if(B_SIG==1)
 pulses++;//moving forward
 if(B_SIG==0)
 pulses--;//moving reverse
//  Serial.println(pulses);
 attachInterrupt(0, A_RISE, RISING);  
}

void B_RISE(){
 detachInterrupt(1);
 B_SIG=1;
 
 if(A_SIG==1)
 pulses++;//moving forward
 if(A_SIG==0)
 pulses--;//moving reverse
//  Serial.println(pulses);
 attachInterrupt(1, B_FALL, FALLING);
}

void B_FALL(){
 detachInterrupt(1);
 B_SIG=0;
 
 if(A_SIG==0)
 pulses++;//moving forward
 if(A_SIG==1)
 pulses--;//moving reverse
//  Serial.println(pulses);
 attachInterrupt(1, B_RISE, RISING);
}


void loop()
{
  //  for the receiver and for the sender you must call sync() once in every loop.
  //  It does not matter where in the loop you call it, 
  //  but receiving at the start and sending at the end makes most sense.
//other variables....................................
sender.observe(aReset);
sender.observe(aStart);
sender.observe(pulses);
sender.observe(aResetOptocoupler);
sender.observe(aResetEncoder);
  //  Tell the receiver what values to sync
  //  Here you need to take care of the order as well!
//other variables...
receiver.observe(pReset);
receiver.observe(pStart);
sender.observe(pPulses);
sender.observe(pResetOptocoupler);
sender.observe(pResetEncoder);
receiver.sync();
  sender.sync();
 
  if (pResetEncoder==1) {

}

 if (pResetEncoder==0) {

}
}

Thanks in advance.

Is this even possible to restart encoder at zero again?

What kind of encoder is it? Absolute position (expensive) or relative position (cheap)? If it is a relative position, you can change the "relative to what" value any time you like.

Detaching and reattaching the interrupt handler is silly. Interrupts don't happen while an ISR is running, so there is no way to interrupt the interrupt service routines.

You don't need 4 ISRs. 2 will do. Use CHANGE as the interrupt type, and in the ISR determine whether the change was to HIGH or to LOW.

HI Thank you for your quick reply. I am new (like a week into arduino coding) so please be easy on me :).

It is a cheap encoder ($3.00 US). I did try to use digital pins (not the interrupt route) but for some reason, it was only 24 pulses per rev vice the 96. Apparently I did not code correctly...so if you suggest I do that, I will try that route.

Still not working. I tend to believe it has something to do with processing and the vsync library function....because if I keep the arduino energized (program running) then stop and restart processing, pulses restarts at zero and "changes" from zero correctly. Any help?

n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } 
    else {
      encoder0Pos++;
    }

  } 

  if ((pPulses==0)&&(encoder0Pos!=0)){
    encoder0Pos = 0;
    encoder0PinALast = LOW;
    n = LOW;
    pulses=0;
    sender.observe(pulses);
    receiver.observe(pPulses);
  }
  pulses=encoder0Pos;

  encoder0PinALast = n;

Any help?

Just this once. http://snippets-r-us.com

I apologize for using snippets because the program is lengthy. I have attached the full codes below.

Thank you in advance.

StepperSeq.ino (4.29 KB)

StepperSeq.pde (22.2 KB)