First off, thanks for this awesome encoder library. Writing encoder-code from scratch is a total pain. I tried once, and failed terribly.
I having some unexpected behavior when using the Encoder as a pointer.
I am using Teensy2++ with Arduino0022
Everything works fine if both pins are interrupt enabled:
Output (as expected):
Basic Encoder Test:
0
1
0
1
2
3
4
5
6
7
8
9
10
However, the output goes goofy when one of the pins is not interrupt enabled:
Output (goofy):
Basic Encoder Test:
-672138537
2143535054
-672138537
2143535054
-672138537
2143535054
-672138537
2143535054
-672138537
I having some unexpected behavior when using the Encoder as a pointer.
I am using Teensy2++ with Arduino0022
Everything works fine if both pins are interrupt enabled:
Code:
#include <Encoder.h>
Encoder *encoderArray[1];
void setup() {
Serial.begin(9600);
encoderArray[0] = new Encoder(0,1); //use pins 0 and 1, both interrupt
Serial.println("Basic Encoder Test:");
}
long oldPosition = -999;
void loop() {
long newPosition = encoderArray[0]->read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}
Output (as expected):
Basic Encoder Test:
0
1
0
1
2
3
4
5
6
7
8
9
10
However, the output goes goofy when one of the pins is not interrupt enabled:
Code:
#include <Encoder.h>
Encoder *encoderArray[1];
void setup() {
Serial.begin(9600);
encoderArray[0] = new Encoder(1,5); //use pins 1 and 5, only pin 1 is interrupt enabled
Serial.println("Basic Encoder Test:");
}
long oldPosition = -999;
void loop() {
long newPosition = encoderArray[0]->read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}
Output (goofy):
Basic Encoder Test:
-672138537
2143535054
-672138537
2143535054
-672138537
2143535054
-672138537
2143535054
-672138537