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.