hey guys, how can i get count two encoder motor with fast respon and true value?
i use bounce library.
this my code
#include <Bounce.h>
// This code increments or decrements a counter based on
// the status of a rotaty encoder
#define pin1 19 // channel A motor 1 with intterupt pin
#define pin2 6 // channel B motor 1
#define pin3 18 //channel A motor 2 with intterupt pin
#define pin4 7 // channel B motor 2
int counter = 0;
int counter2 = 0;
Bounce bouncer1 = Bounce( pin1,1 );
Bounce bouncer2 = Bounce( pin3,1 );
void setup() {
pinMode(4,OUTPUT); //mkanan
pinMode(5,OUTPUT); //mkiri
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
Serial.begin(9600);
}
void loop() {
encoder();
analogWrite(3, 200);
analogWrite(2, 200);
}
void encoder()
{
bouncer1.update ();
bouncer2.update ();
if ( bouncer1.risingEdge()) {
if (digitalRead(pin1)){
counter++;
}
}
if ( bouncer2.risingEdge()) {
if (digitalRead(pin4)){
counter2++;
Serial.println(counter2);
}
}
Serial.print("motor 1: ");
Serial.print(counter);
Serial.print(" motor 2: ");
Serial.println(counter2);
}
thanks