I wrote a little class for a rotary encoder which outputs an int for the number of clicks it has been turned.
This can be positive or negative depending on roational direction.
Now I want to use this encoder to manipulate the target time of a countdown timer.
This time is an unsigned long to match with millis().
What I am now basically trying is:
targetTime += Encoder.ticks(), which works perfectly for positive "ticks", but fails for negative, due to the arithmetics of the negative number (binary -1 equals binary 255). So I totally understand why the routine fails on negative ticks I have no idea how to fix it.
Any suggestions?
Sorry, bin es so gewohnt, technischen Kram auf Englisch zu schreiben.
Es hat sich geklärt, es ging um einen Encoder-Wert aus einer Graytab. Also
uint8_t graytab[16] = {-1, 1, 0,0,...}
encoder::returnValue() {return blabla graytab[0];}
unsigned long time = time + encoder.ReturnValue();
Das geht natürlich murks, weil uint8_t halt UUUUUunsigned ist
Ich hatte überall gesucht, nur die blöde Tabelle, die ich seit (C-code-)Ewigkeiten benutze ich nicht angezweifelt (wobei ich mich frage, wieso das in C immer funktioniert hat).
mit