Ho copiato pari-pari l'esempio sul sito di arduino (Arduino Playground - RotaryEncoders) e l'ho modificato così perchè volevo avere un valore tra 0 e 24 ma non mi funziona...mi sapete indicare perchè continua ad andare sotto lo zero oppure sopra il 24?
int val;
int encoder0PinA = 2;
int encoder0PinB = 3;
int encoder0Pos = 12;
int encoder0PinALast = LOW;
int n = LOW;
void setup() {
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
Serial.begin (9600);
}
void loop() {
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
if (encoder0Pos <= 0){
encoder0Pos == 24;}
} else {
encoder0Pos++;
if (encoder0Pos >= 24){
encoder0Pos == 0;}
}
Serial.print (encoder0Pos);
Serial.print ("/");
}
encoder0PinALast = n;
}
grazie!!