
سلام دوستان
این مدل [ روتاری انکودر نوری 100 درجه دو فاز ] را خریداری کردم و با توجه به آموزش راه اندازی سایت کافه ربات و کدهای آن، تعداد 200 پالس در یک دور کامل می دهد. ولی با استفاده از کتابخانه (ENCODER ) این روتاری، 400 پالس در یک دور کامل را می دهد.
سئوال:
- اولا مگر نباید روتاری 100 درجه، 100 پالس در یک دور کامل بدهد؟
- دوما نمی دونم کدوم درسته و برای کار کردن بعدا مشکلی ایجاد نمی کند؟
پیشاپیش از راهنماییتان ممونم.
- کدهای کافه ربات و تعداد 200 پالس برای روتاری انکودر نوری 100 درجه :
/* HN3806-AB-Rotary-Encoder modified on 12 oct 2020 by Amir Mohamad Shojaee @ Electropeak https://electropeak.com/learn/Based on electricdiylab.com Example
*///This variable will increase or decrease depending on the rotation of encoder
volatile long x , counter = 0;void setup() {
Serial.begin (9600);
pinMode(2, INPUT_PULLUP);pinMode(3, INPUT_PULLUP);
attachInterrupt(0, A, RISING);
attachInterrupt(1, B, RISING);
}void loop() {
// Send the value of counter
if( counter != x ){
Serial.println (counter);
x = counter;
}
}void A() {
if(digitalRead(3)==LOW) {
counter++;
}else{
counter–;
}
}
void B() {
if(digitalRead(2)==LOW) {
counter–;
}else{
counter++;
}
}
- کدهای کتابخانه ENCODR و تعداد 400 پالس برای روتاری انکودر نوری 100 درجه :
/* Encoder Library - Basic Example * http://www.pjrc.com/teensy/td_libs_Encoder.html * * This example code is in the public domain. */#include <Encoder.h>
// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(5, 6);
// avoid using pins with LEDs attachedvoid setup() {
Serial.begin(9600);
Serial.println(“Basic Encoder Test:”);
}long oldPosition = -999;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}
