Go Down

Topic: two encoder motor fast respone (Read 379 times) previous topic - next topic

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

MarkT

What kind of encoders are these?
[ I won't respond to messages, use the forum please ]

i use 2 motor encoder Metal Gearmotor 37Dx57L mm with 64 CPR Encoder. for full specification can you read in http://tokorobot.co.id/product/1446/TOKO%20ROBOT%20-%20100:1%20Metal%20Gearmotor%2037Dx57L%20mm%20with%2064%20CPR%20Encoder

please help me. thanks

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy