-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Description
I want to have two encoders in one script. I assumed it would work like this:
#include <Arduino.h>
#include <BasicEncoder.h>
#include <TimerOne.h>
BasicEncoder encoder(8, 9);
BasicEncoder encoder2(10, 11);
void timer_service() {
encoder.service();
encoder2.service();
}
void setup() {
Serial.begin(230400);
Serial.println("Starting..");
Timer1.initialize(1000);
Timer1.attachInterrupt(timer_service);
}
void loop() {
int encoder_change = encoder.get_change();
if (encoder_change) {
Serial.print("Encoder 1: "); Serial.println(encoder.get_count());
}
int encoder2_change = encoder2.get_change();
if (encoder2_change) {
Serial.print("Encoder 2: "); Serial.println(encoder2.get_count());
}
}
However, when I use this code, both values will change when I turn any of the rotary-encoders, and sometimes they enter a feedback-loop where both of the values will change (equally) endlessly.
I am really bad at Arduino/C, so am I doing something obvious wrong, or is the error somewhere else than on my side here?
Metadata
Metadata
Assignees
Labels
No labels