this should be simple, but evidently its way over my head.
I'm using the new encoder library, loaded the basic code and it works great. So now I want to DO something with it, great.
So I set up pin 13 as an out put and analog write the value from the encoder to it, sorta works.
first issue is obvious, the basic encoder example sets up the variables oldPosition and newPosition as longs, so obviosly this will cause issues on the eight bit PMW.
Easy fix, i just changed the longs to bytes, sweet.
Now the only thing that i cant seem to fix is it will roll over at 255 to 0, or backwards from 0 to 255.
I tried going back to a long and using the constrain function, this kept it from rolling over, but if i turned the encoder 3 full turns past 255, i had to turn it back 3 full turns before it would start counting down.
I would really like to use an encoder for lots of projects, but if i cannot force usable minimums and maximums to the data coming from it, its kind of useless.
any help??
/* 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(2, 3);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}
byte oldPosition = 0;
void loop() {
byte newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}