atm I turn the encoder maybe 1/6 turns and its already showing me 360
I need to make it to show 360 after I've turned the encoder 360
And yes the code needs to stop at 0 and at 360.
I am trying to make antenna rotator with logic: after antenna turns 360 from starting point, it stops so no wires break. only way back is to turn motors other way closer to 0.
But first I need to raise the range of the encoder somehow.
I've tried lastPos = newPos / 800; etc..... without luck.
If I take the ROTARYMAX value to the sky like 36000000
then ONE full turn is 6000 on serial monitor.
4 wires, black and red so gnd and 5v.
then 2 wires are connected to uno's pin 12 and 13.
No resistors etc...
this is same encoder than in my last project and there I got it working easy.
#include <Encoder.h>
Encoder windvane(A2, A3);
void setup() {
Serial.begin(9600);
}
int old_pos = windvane.read();
const char wd[][4] = {{" N "}, {"NNE"}, {" NE"}, {"ENE"}, {" E "}, {"ESE"}, {" SE"}, {"SSE"}, {" S "}, {"SSW"}, {" SW"}, {"WSW"}, {" W "}, {"WNW"}, {" NW"}, {"NNW"}};
void loop() {
int i = windvane.read();;
i = windvane.read();
if (i != old_pos) {
Serial.println(wd[abs(i % 2400)/280]);
old_pos = windvane.read();
}
}
this is my last project code. almost same thing.
Serial.println(wd[abs(i % 2400)/280]);
takes the value and does 2400/280 and I get perfect one turn = 360degree
Now I have to somehow make same 2400/280 here but I have no idea where I have to add it