Hi, I'm developing a project that uses a rotary encoder and an rfid reader I have both working separately however I have no idea how to combine both of these scripts together so I can use these 2 separate sensor values in other programs I am using to complete this project. I'm just wondering could anyone point me in the right direction of what I'll need to learn to do this because coding isn't my strongest point. I'm working with an optical encoder so I'm not using any debouncing code.
Here is the encoder code I am working with:
int pulses, A_SIG=0, B_SIG=1;
int digitalInput5 = 5; // change color
int value5 = '0';
void setup(){
attachInterrupt(0, A_RISE, RISING);
attachInterrupt(1, B_RISE, RISING);
pinMode(digitalInput5,OUTPUT);
Serial.begin(19200);
}//setup
void loop(){
value5 = digitalRead(5);
if (value5 ){
pulses=0;
}
}
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);
}
I'm attaching the rfid reader code but I am mainly reworking it from Jeremy Blums tutorials on youtube. If anyone could tell me how to go about doing this or if the code I'm trying to combine is incompatible it'll be much appreciated.
read_rfid2.ino (2.38 KB)