Video není dostupné.
Omlouváme se.
Rotary Encoder Incremental rotary Encoder How to use it with Arduino
Vložit
- čas přidán 15. 08. 2024
- Rotary Encoder Incremental rotary Encoder How to use it with Arduino
Link Sketch download
goo.gl/s5fV59 ::::::::::: SUPPORT CHANNEL ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : goo.gl/1m8Dg2
Don't forget to subscribe!
I just hooked up a 10-30v fairly large encoder, fed the encoder 12v @ 70ma or so and worked like a champ. Shaft is a lot hard than yours to turn but works perfect first try. Counts 1-65k and back down no problem. Thanks for simple and clear video.
In some case, it wont work with board's 5v .. if you want to use the board power ONLY, then you can open it up and short the outer pins of LM7805 (78m05).. Remeber its only if you dont want to use any other external power source.
Hi Everyone! I´ve tried this code in arduino mega and works just fine. ( I have the same encoder only 360ppr) but when I try ir in arduino leonardo the counter stays around the same number. It starts working when I modify one of the interrupts to FALLING or if i just unplug uno of the pins. But only increments the Value. Does anyone knows what could be the issue. Thanks.
This is spectacular sketch for Arduino Thanks
Why do people think it appropriate to make a technical video with hideous music hammering away in the background and no commentary.
Is the reading you are showing in RPM?
I think the encoder you are using (see 0:14) has 600 pulses per revolution, not 400. Yours is type ...-600BM-... Thanks for the video and the code!
Also this code is incrementing counter on both phases, so it 1200 pulses per rotation
is it matter.all is it doing count pulses not revolutions xD
Thank You Very Much ! for ilustration "
Good job .if I went put stepper motor withe encoder how I do that
The encoder detects movement in both directions but loses its reference zero...does anyone knows why?
Thank you for sharing this video with us. There is one point to enhance the code: add max and minimum counter limits then flip the counter when reaching the limit such as:
void countClamp () { // clamp count from QMIN to QMAX:
if (counter > QMAX) {
counter = QMIN;
}
else if (counter < QMIN) {
counter = QMAX;
}
This function should be verified whenever updating the counter
I think in your case limits would be
long temp,counter = 0; //sign should be considered
#define QMAX 1199
#define QMIN 0
Hi A R, looking for some help, would this make the code deal with minus numbers as it currently goes to 65000 something when it passes zero? Any elp would be appreciated, been stuck on this too long. Thanks
how to solve limit counter ? how
Make sure that if you're using velocity as a control input that you also account for the rollover. E.g. if the QMAX was 1000 and it goes from 980 to 20 in one dt timestep, you have to do some math. 1000-(prevCount=980) + (newCount=20) to get the 40 counts that the encoder rotated. Do this in reverse if you hit QMIN. If you don't do this, the counts/dt would be 20-980 which would give a speed of -960counts/dt which will throw off any control loop you may have
Anyone knows the max speed readable? I don't think the arduino can read all values if the encoder reaches 5000 rpm
Can you convert the ENCODER FREQ to RPM Function ?Looking forward to another quick video
yo tengo exactamente ese mismo encoder pero mi problema es que solo aumenta, no disminuye, creo que vino con defectos
Hola, espero que no haya llegado tarde pero el encoder funciona, lo que pasa es que el codigo tiene deteccion de interrupciones en HIGH cuando deberia ser CHANGE modifica eso y funcionara
@@angelabreu2676 ya voy para 3 años con mi volante g29 ya que nunca pude resolverlo 😞 pero igual gracias
I have a homemade steering wheel project for games, just like Logitec, but I don't have the sketch to use the encoder, and I also can't load the sketches into the Arduino. what to do?
can i use this as a masering wheel for Cut to lenth machine
Thanks. The only one worked codes on youtube.
I have an AC motor which turns 10 RPM . The motor turns a shaft with a chain . I want to measure and stop the motor when to chain travels 4 meters. Is this possible with this encoder.
I have exactly the same encoder, it came to me today from Aliexpress and if I don't put pullups on it, it doesn't work for me, I put the outputs on the oscilloscope and I see the signals very very attenuated, with pullups it works very well. What can it be due to, will I have failed? Regards.
That's it, I'm not using it with Arduino, and I can't activate the internal pullups of the microcontroller, because I have opto-isolated input. The output of this encoder in NPN open collector, that's why I need to put external pull ups resistors. Regards.
If the motor does 3.500 rpm, the encoder 1.000 pulses, does the arduino have enough capacity or are pulses lost? Thks
Can you please tell me how would you use this to calculate angle, like the line of code that should be added?
//TRY THIS
// defines pins numbers
const int stepPin = 10;
const int dirPin = 11;
const int enPin = 12;
float pulsesR = 6400;
float pulsesL = 6400;
const int pulsedelay = 0;
int cycledelay= 20;
//--------------------ENCODER Variables START-------------------------
float counter;
int Left;
int Right;
int leftPin = 2;
int rightPin = 3;
const int Home = 999;
float degree;
//--------------------ENCODER Variables FINISH-------------------------
void setup() {
Serial.begin(115200);
// Sets the two pins as Outputs
pinMode(6, INPUT_PULLUP);
pinMode(7, OUTPUT);
pinMode(4, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
//--------------------ENCODER Setup START-------------------------
pinMode(leftPin, INPUT_PULLUP); // internal pullup input pin leftPin
pinMode(rightPin, INPUT_PULLUP); // internal pullup input pin rightPin
pinMode(Home,INPUT);
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr leftPin on moust Arduino.
attachInterrupt(0, SwingRight, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr rightPin on moust Arduino.
attachInterrupt(1, SwingLeft, RISING);
//--------------------ENCODER Setup FINISH-------------------------
}
void loop() {
//--------------------ENCODER Loop START-------------------------
degree = counter /2;
// Send the value of counter
if( digitalRead (Home) == HIGH ){
// temp = counter;
counter = 0;
Serial.println (degree,0);
}
digitalRead(leftPin);
digitalRead(rightPin);
//--------------------ENCODER Loop FINISH-------------------------
int sensorVal6 = digitalRead(6);
if (sensorVal6 == LOW) {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < pulsesR; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(pulsedelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(pulsedelay);
// degree++;
// Serial.println(degree / 35.55555555555556 ,0);
digitalWrite(7, HIGH);
}
} else {
digitalWrite(7, LOW);
delay (50);
}
delay(cycledelay);
delay(cycledelay); // One second delay
int sensorVal4 = digitalRead(4);
if (sensorVal4 == LOW) {
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < pulsesL; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(pulsedelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(pulsedelay);
// degree--;
// Serial.println(degree/ 35.55555555555556,0);
digitalWrite(5, HIGH);
}
} else {
digitalWrite(5, LOW);
}
delay(cycledelay);
}
//--------------------ENCODER SwingRight Interrupt START------------------------
void SwingRight() {
// ai0 is activated if DigitalPin nr leftPin is going from LOW to HIGH
// Check pin rightPin to determine the direction
if(digitalRead(rightPin)==LOW + LOW + HIGH) {
counter--;
Serial.print(" SwingingRight at ");
Serial.println (degree,0);
Right = degree;
}else{
counter++;
}
}
//--------------------ENCODER SwingRight Interrupt FINISH------------------------
//--------------------ENCODER SwingLeft Interrupt START------------------------
void SwingLeft() {
// ai0 is activated if DigitalPin nr rightPin is going from LOW to HIGH
// Check with pin leftPin to determine the direction
if(digitalRead(leftPin)==LOW + LOW + HIGH) {
counter++;
Serial.print("SwingingLeft at ");
Serial.println (degree,0);
Left = degree;
}else{
counter--;
}
}
//--------------------ENCODER Swingleft INterrupt FINISH------------------------
Like 1.3 K ❤ 👏👏👏
you programmed it with rising edge on each pins A and B right?
Hi does it work? With arduino leonardo, i´ve uploaded the code and connected the wired scheme and in the monitor shows 1 2 and when i turn the encoder it doesnt go to 50
My homemade Six Digit, 20MHz, CD74HC192 Up-Down counter circuit counts Quadrature Encoder pulses at 20Mhz speeds. And seems to be many times faster than using my PIC16F887 microcontrollers.
Can you tell me why?
HI Maker Tutor, i brought Rotary Encoder HQK38H6-600N-G5-24 form china use your Sketch the problem is the encoder reading always increment if i turn forward or backwards the staff.
thank you for this video but i want to read this value and control a DC motor with the same value so the encoder and the motor have the same speed
thanks
Hello, what if I want see negative numbers want to see, what should I change in code ? ,thank you.
hi. i have e38s65 400b g24n rotary encoder 5v-24v it is not work with arduino routary encoder code. how can i solve ?
Hi, Sir. can we use raspberry pi pico to read the incremental rotary encoder?
ohhhhhhhhhhhhhhhhhhh 👍👍👍👍👏👏👏👏
I need, can you help. i want to make a long cloth.between 1 meter to 10 meter.so how to do the code and use the suitable rotary encoder?
Nice little video, code works a treat. Thanks
May I know what type arduino u used?thanks.GBU
Hi, great project. Do you know about the maximum frecuency reading of arduino
What is the software used to view the results mam in your pc
I want to move it to specific number of turn and want to control position of quadrature encoder motor using coding
Excellent video
Can the out put of the Arduino Uno be given to an display unit. IF so please make a video on it.
Muchas gracious from India
can we calculate accurate angle using this??
Is it possible to have a design that will allow the incremental encoder to act like an absolute encoder?
No
@@hurairtariq1 I did it and it worked.
Hola,pueden compartir ese codigo para contar pulsos de encoder rotativo?
do you have the code to connect to the lcd display with this type of encoder?
Hi
Has anyone tried to do the same with a jetson nano or raspberry pi for the same model of the encoder ? If yes then please share the code.
@maker tutor , i am having problem that when i rotate it in anti clock wise direction it shows 65535, kindly tell me how to resolve that issue.
I has the same problem. Change variable type from int(int stores a 16-bit) to long (32-bit).
volatile unsigned int temp, counter = 0 ,what should I write to do it ??? thanks
@@muratcanbarut64 You figured it out I myself can’t understand?
I have an encoder very similar to this one, having no luck writing a code to do what I need, can you help. I want to use a timing belt and sprocket to measure how far the belt moves (with extreme accuracy) and display on a LCD display.
float temp;
int counter = 0;
int statePrevious;
boolean stateLeft;
boolean stateRight;
int setLeft;
int setRight;
int Led7=7;
int Led8=8;
// volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder
void setup() {
Serial.begin (115200);
pinMode(2, INPUT_PULLUP); // internal pullup input pin 2
pinMode(3, INPUT_PULLUP); // internal pullup input pin 3
pinMode(Led7, OUTPUT);
pinMode(Led8, OUTPUT);
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
attachInterrupt(0, ai0, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
attachInterrupt(1, ai1, RISING);
}
void loop() {
// Send the value of counter
if( counter != temp ){
temp = counter;
}
}
void ai0() {
// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
// Check pin 3 to determine the direction
if(digitalRead(3)==LOW) {
stateRight = true;
stateLeft = false;
if (stateRight == true && stateLeft == false) {
Serial.println ("Going Right ");
setLeft = counter - counter - counter + 1;
Serial.println (temp,0);
Serial.print (" Set left to ");
Serial.println (setLeft);
digitalWrite (Led7, HIGH);
digitalWrite (Led8, LOW);
// send stepper to last (setLeft);
}
counter--;
}else{
counter++;
}
}
void ai1() {
// ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
// Check with pin 2 to determine the direction
if(digitalRead(2)==LOW) {
stateRight = false;
stateLeft = true;
if (stateRight == false && stateLeft == true) {
Serial.println ("Going Left ");
setRight = counter - counter - counter - 1 ;
Serial.println (temp,0);
Serial.print (" Set Right to ");
Serial.println (setRight);
digitalWrite (Led7, LOW);
digitalWrite (Led8, HIGH);
// send stepper to last (setLeft);
}
counter++;
}else{
counter--;
}
}/*change detection
rotary encoder type LPD3806-360BM-G5-24C
J733 purchased on ebay*/
Ese motor de paso y encodet se puede conectar a un driver híbrido,para motor de paso y encoder.
Can you control two encoders at once?
how can we measure length travelled using that encoder?
2*pi*radius gives you the length traveled in a whole revolution (radius = outer radius of pulley attached to the axis of the encoder for example).
Devide this length by the number of pulses per revolution, in this case 400. Now you now your displacement per pulse.
Where does the rotary Encoder buy?
can i use this project in unojoy
Practico de implementar, gracias.
thanks a lot!!!!!!
The enconder has 600 pulses per channel?
Bonjour, j'ai un code de 1200, je veux convertir en 360, puis-je avoir un code
Muchas gracias por el aporte (Y)
Works perfectly! Thanks!!!
its limited 65535 ? and dont show negative numbers?
Can I use this code for arduino Leonardo r3? Help please
very good, help a lot, thank u!
is this code limited 65535?
do you know how to wiring this encoder with cnc ?
Thanks for the video and the code
Tks, it worked!
does anyone know how to use two rotary encoders with this code??
how to calculate rpm from encoder pulses? please help me
Did you get an answer ؟
watch my comment
Very good
Wow, until I watched this video, I had no idea how to plug four wires into an Arduino
helped a lot, thanks
Can this code stand foe high speed encoder?
used ur code and the same ecoder, but getting wrong result. with one step i get both signals(+ and _) and result is like 1-0-1-0-1-0-1-0-1..... if i detach one logic pin i get only one direction of counting no matter of direction of rotation. it counts impulses correctly but only pluses or only minuses. cant understand why does it do this way...((
It happened the same to me but only in Leonardo. In Mega works fine. Dont know why...
@@andrescarlini2071 you have to change the code, see www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
attachInterrupt(digitalPinToInterrupt(2), ai0, RISING);
attachInterrupt(digitalPinToInterrupt(3), ai1, RISING);
/*I have been trying to these encoders to read oscillations left to right of a pendulum. I have tried interrupts, switch states and every type of code I can think of. I can get reading from center of zero and - to the left , + to right, but cannot get it to return to zero. It drifts one way or the other. Does anyone have a sketch I can try? Here is an example sketch I pulled out the Stepper code. */
// defines pins numbers
const int stepPin = 10;
const int dirPin = 11;
const int enPin = 12;
float pulsesR = 6400;
float pulsesL = 6400;
const int pulsedelay = 0;
int cycledelay= 20;
//--------------------ENCODER Variables START-------------------------
float counter;
int Left;
int Right;
int leftPin = 2;
int rightPin = 3;
const int Home = 999;
float degree;
//--------------------ENCODER Variables FINISH-------------------------
void setup() {
Serial.begin(115200);
// Sets the two pins as Outputs
pinMode(6, INPUT_PULLUP);
pinMode(7, OUTPUT);
pinMode(4, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
//--------------------ENCODER Setup START-------------------------
pinMode(leftPin, INPUT_PULLUP); // internal pullup input pin leftPin
pinMode(rightPin, INPUT_PULLUP); // internal pullup input pin rightPin
pinMode(Home,INPUT);
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr leftPin on moust Arduino.
attachInterrupt(0, SwingRight, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr rightPin on moust Arduino.
attachInterrupt(1, SwingLeft, RISING);
//--------------------ENCODER Setup FINISH-------------------------
}
void loop() {
//--------------------ENCODER Loop START-------------------------
degree = counter /2;
// Send the value of counter
if( digitalRead (Home) == HIGH ){
// temp = counter;
counter = 0;
Serial.println (degree,0);
}
digitalRead(leftPin);
digitalRead(rightPin);
//--------------------ENCODER Loop FINISH-------------------------
int sensorVal6 = digitalRead(6);
if (sensorVal6 == LOW) {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < pulsesR; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(pulsedelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(pulsedelay);
// degree++;
// Serial.println(degree / 35.55555555555556 ,0);
digitalWrite(7, HIGH);
}
} else {
digitalWrite(7, LOW);
delay (50);
}
delay(cycledelay);
delay(cycledelay); // One second delay
int sensorVal4 = digitalRead(4);
if (sensorVal4 == LOW) {
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < pulsesL; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(pulsedelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(pulsedelay);
// degree--;
// Serial.println(degree/ 35.55555555555556,0);
digitalWrite(5, HIGH);
}
} else {
digitalWrite(5, LOW);
}
delay(cycledelay);
}
//--------------------ENCODER SwingRight Interrupt START------------------------
void SwingRight() {
// ai0 is activated if DigitalPin nr leftPin is going from LOW to HIGH
// Check pin rightPin to determine the direction
if(digitalRead(rightPin)==LOW + LOW + HIGH) {
counter--;
Serial.print(" SwingingRight at ");
Serial.println (degree,0);
Right = degree;
}else{
counter++;
}
}
//--------------------ENCODER SwingRight Interrupt FINISH------------------------
//--------------------ENCODER SwingLeft Interrupt START------------------------
void SwingLeft() {
// ai0 is activated if DigitalPin nr rightPin is going from LOW to HIGH
// Check with pin leftPin to determine the direction
if(digitalRead(leftPin)==LOW + LOW + HIGH) {
counter++;
Serial.print("SwingingLeft at ");
Serial.println (degree,0);
Left = degree;
}else{
counter--;
}
}
//--------------------ENCODER Swingleft INterrupt FINISH------------------------
Hello.. I'm having the same issue. Have you find the solucion ? If yes let me know
Can it keep up with a stepper motor running at 30000 mm/min? I would like to use it in high speed gcode application
This rotary encoder can running at 6,000 rpm , convert from rpm to mm/min I don't know sorry
Maker Tutor it's okay :) thanks!
Do you know what encoder this is Brand and Serial Number Please
or a link to where i can buy it =)
thanks for the video.
but how can i use encoder to meassure angular speed?
any ideas????????
thank you very much
excelente..gracias
Hi dear Can you send me Encoder program pictures
Muchas gracias !!
Thanks for the code
how about this encorder with esp32?
how to detect speed of motor by this pls.
what details of Arduino please ?
Nice.
counter limit is 65535 ?! why?
no no your code is working . but how can i have negative numbers?
Круто, работает!
How to use two encoder in arduino
Thanks ...!!!
Hello Bro! What Pin G is used for?
Pin G = Ground or GND
Bellissimo progetto , mi aiuti a realizzarlo ? francesco da Palermo
How can i contact with mail adress?
How to open the data inputs information screen please)?
ctr+shift+m
@@theragavelan Yeah, I've got that. That encoders should have separate 12V power suplly to work. And that's why I asked that couse that showed some wrong thingies in that screen with defolt 5v from arduino. So was wondered if that a right one. )
400P/R is how many can divide angles ? can use for 0.01 degree ?
365/400 = .9 deg/pulse, so no?
yes
0.01 deg means you need 360 * 100 pulses then you need 36000 puls.
that's mean you need 36000 / 400 = 90 encoder revelution per one turn of the motor shaft.
so use gears to make this posible and you will get 0.01 degree per puls
// defines pins numbers
const int stepPin = 10;
const int dirPin = 11;
const int enPin = 12;
float pulsesR = 6400;
float pulsesL = 6400;
const int pulsedelay = 0;
int cycledelay= 20;
//--------------------ENCODER Variables START-------------------------
float counter;
int Left;
int Right;
int leftPin = 2;
int rightPin = 3;
const int Home = 999;
float degree;
//--------------------ENCODER Variables FINISH-------------------------
void setup() {
Serial.begin(115200);
// Sets the two pins as Outputs
pinMode(6, INPUT_PULLUP);
pinMode(7, OUTPUT);
pinMode(4, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
//--------------------ENCODER Setup START-------------------------
pinMode(leftPin, INPUT_PULLUP); // internal pullup input pin leftPin
pinMode(rightPin, INPUT_PULLUP); // internal pullup input pin rightPin
pinMode(Home,INPUT);
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr leftPin on moust Arduino.
attachInterrupt(0, SwingRight, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr rightPin on moust Arduino.
attachInterrupt(1, SwingLeft, RISING);
//--------------------ENCODER Setup FINISH-------------------------
}
void loop() {
//--------------------ENCODER Loop START-------------------------
degree = counter /2;
// Send the value of counter
if( digitalRead (Home) == HIGH ){
// temp = counter;
counter = 0;
Serial.println (degree,0);
}
digitalRead(leftPin);
digitalRead(rightPin);
//--------------------ENCODER Loop FINISH-------------------------
int sensorVal6 = digitalRead(6);
if (sensorVal6 == LOW) {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < pulsesR; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(pulsedelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(pulsedelay);
// degree++;
// Serial.println(degree / 35.55555555555556 ,0);
digitalWrite(7, HIGH);
}
} else {
digitalWrite(7, LOW);
delay (50);
}
delay(cycledelay);
delay(cycledelay); // One second delay
int sensorVal4 = digitalRead(4);
if (sensorVal4 == LOW) {
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < pulsesL; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(pulsedelay);
digitalWrite(stepPin,LOW);
delayMicroseconds(pulsedelay);
// degree--;
// Serial.println(degree/ 35.55555555555556,0);
digitalWrite(5, HIGH);
}
} else {
digitalWrite(5, LOW);
}
delay(cycledelay);
}
//--------------------ENCODER SwingRight Interrupt START------------------------
void SwingRight() {
// ai0 is activated if DigitalPin nr leftPin is going from LOW to HIGH
// Check pin rightPin to determine the direction
if(digitalRead(rightPin)==LOW + LOW + HIGH) {
counter--;
Serial.print(" SwingingRight at ");
Serial.println (degree,0);
Right = degree;
}else{
counter++;
}
}
//--------------------ENCODER SwingRight Interrupt FINISH------------------------
//--------------------ENCODER SwingLeft Interrupt START------------------------
void SwingLeft() {
// ai0 is activated if DigitalPin nr rightPin is going from LOW to HIGH
// Check with pin leftPin to determine the direction
if(digitalRead(leftPin)==LOW + LOW + HIGH) {
counter++;
Serial.print("SwingingLeft at ");
Serial.println (degree,0);
Left = degree;
}else{
counter--;
}
}
//--------------------ENCODER Swingleft INterrupt FINISH------------------------
i'm confused: that ugly hand is not a girl's hand
LPD3806-600BM
oi boa tarde, eu não conseguir
my encoder reads 65535 per revolution at 115200 Baud
I has the same problem. Change variable type from int(int stores a 16-bit) to long (32-bit).
O conteúdo é relevante mas veja no mudo porq a música é um lixo
65535