un saluto a tutto il forum…
avevo bisogno dei vostri consigli perchè il mio encoder
mi riporta valori errati o a volte mancanti…
mi potete aiutare a capire come risolvere?
static int encoder0PinA = 3;
static int encoder0PinB = 4;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
int rotazione = 0;
void setup() {
pinMode (encoder0PinA, INPUT);
digitalWrite(encoder0PinA, HIGH); //Pullup enabled
pinMode (encoder0PinB, INPUT);
digitalWrite(encoder0PinB, HIGH); //Pullup enabled
Serial.begin(9600);
}
int encoder() {
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
rotazione = 1;
}
else {
encoder0Pos++;
rotazione = 1;
}
if (encoder0Pos == -1) encoder0Pos = 130;
else if (encoder0Pos == 131) encoder0Pos = 0;
}
Serial.println (encoder0Pos);
}
void loop() {
// put your main code here, to run repeatedly:
}
aggiungo anche immagine di collegamento.
grazie a tutti per l’aiuto.