/* Encoder Library - TwoKnobs Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/
#include <Encoder.h>
// Change these pin 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 knobLeft(SS, 8);
Encoder knobRight(MISO, 13);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("TwoKnobs Encoder Test:");
}
long positionLeft = -999;
long positionRight = -999;
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
if (newLeft != positionLeft && newLeft % 4 ==0 || newRight != positionRight && newRight % 4 ==0 ) {
Serial.print("Left = ");
Serial.print(newLeft/4);
Serial.print(", Right = ");
Serial.print(newRight/4);
Serial.println();
positionLeft = newLeft;
positionRight = newRight;
}
// if a character is sent from the serial monitor,
// reset both back to zero.
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knobLeft.write(0);
knobRight.write(0);
}
}
After adding:
% 4 ==0
and val/4
I have counting by 1. But it doesnt works properly for left knob. SS and 8 - they are PCINT. For right knob work ... good but not ideal for all steps - MISO and 13 pin, only MISO is PCINT.
Problem with left knob:
- start from 0 position/count, turn right of leftKnob- I got nothing. Then turn right of rightKnob - i got -1 (this move for check if leftKnob has still 0 count):
11:08:36.687 -> Reset both knobs to zero
11:08:36.687 -> Left = 0, Right = 0
11:08:53.421 -> Left = 0, Right = -1
11:08:53.888 -> Left = 0, Right = 0
then turn left leftKnob:
then I got new print in serial monitor of "0" for leftKnob:
11:09:48.631 -> Left = 0, Right = 0
again turn left:
11:10:28.146 -> Left = 1, Right = 0 , its ok
then turn right, should go to 0, but it stuck at 1, nothing change in serial monitor, but after turning rightKnob ... I got "0" for leftknob and -1 for rightknob
11:11:04.374 -> Left = 0, Right = -1
maybe problem is with leftKnob because it uses both pins as PCINT? Maybe it would be good to turn off PCINT for second pin of leftKnob?


