Ciao a tutti. Oggi stavo giacando con un encoder elettronico da 500 impulsi/rpm e ho scritta questo programma
/*
Name: encoder.ino
Created: 12/03/2019 11:10:02
Author: airma
*/
const int encoderpiu = 2;
const int encodermeno = 3;
byte contatore = 0;
int oldcontatore = 0;
int oldencoder = LOW;
int encoder = LOW;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
pinMode(encoderpiu, INPUT);
pinMode(encodermeno, INPUT);
pinMode(10, OUTPUT);
}
// the loop function runs over and over again until power down or reset
void loop() {
encoder = digitalRead(2);
if((oldencoder ==LOW) && (encoder == HIGH)){
if (digitalRead(3) == LOW){
contatore --;
}else{
contatore ++;
}
//oldencoder = encoder;
}
oldencoder = encoder;
if ((contatore) != (oldcontatore)) { // blocco la stampa quando non preme i pulsanti
Serial.print(" contatore = ");
Serial.println(contatore);
oldcontatore = contatore;
}
analogWrite(10, contatore);
}
il programma fa quello che io voglio però quando vado a vedere sul terminale di arduino vedo questo
contatore = 245
10:22:06.504 -> contatore = 244
10:22:06.544 -> contatore = 243
10:22:06.544 -> contatore = 242
10:22:06.544 -> contatore = 241
10:22:06.584 -> contatore = 240
10:22:06.624 -> contatore = 239
10:22:06.624 -> contatore = 238
contatore = 239
contatore = 240
contatore = 239
contatore = 240
é vero che ho selezionato la spunta su visualizza orario ma dovrebbe farlo sempre