I am trying to set higher level boundaries, but I am having issues as I cannot set a max boundary that works like intended.
SetCount() can be set in setup(), but not again in code. It keeps on counting beyond the boundary in hardware, so it will take many additional rotations to return. Clear() sets it to 0, I can't setCount() after clearing. Pause() will always keep the same position so resume() will never be called. If I resume and pause each time, it will keep adding to the count if going clockwise...
Any suggestions?
Thanks :)
#include <ESP32Encoder.h>
ESP32Encoder encoder;
long oldPosition = 0;
void setup () {
encoder.attachHalfQuad ( 13, 12 );
encoder.setCount ( 0 );
Serial.begin ( 115200 );
}
long encFunc (ESP32Encoder d, long min_boundary, long max_boundary, long stepsize) {
long position = (d.getCount() / 2) * stepsize;
if (position < min_boundary) {
d.clearCount();
position = min_boundary;
} else if (position > max_boundary) {
d.setCount(max_boundary * 2);
position = max_boundary;
}
return position;
}
void loop () {
long newPosition = encFunc(encoder, 0, 100, 5);
if (oldPosition != newPosition) {
Serial.println("Encoder 1: ");
Serial.println(newPosition);
oldPosition = newPosition;
}
}
Hi,
I am trying to set higher level boundaries, but I am having issues as I cannot set a max boundary that works like intended. SetCount() can be set in setup(), but not again in code. It keeps on counting beyond the boundary in hardware, so it will take many additional rotations to return. Clear() sets it to 0, I can't setCount() after clearing. Pause() will always keep the same position so resume() will never be called. If I resume and pause each time, it will keep adding to the count if going clockwise...
Any suggestions?
Thanks :)