Pages: [1]   Go Down
Author Topic: two encoder motor fast respone  (Read 294 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* Capture.PNG (10.11 KB, 196x281 - viewed 16 times.)
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11718
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What kind of encoders are these?
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: