// Lecture d'un potentiomètre sur A0 et affichage
// UNIQUEMENT lorsque la valeur change
#define PIN_POT A0 // Broche du potentiomètre
const unsigned long INTERVAL = 50; // Intervalle entre deux lectures (ms)
int lastValue = -1; // Valeur précédente initialisée hors plage
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
unsigned long now = millis();
if (now - lastMillis < INTERVAL) {
return; // on attend le prochain intervalle
}
lastMillis = now;
int currentValue = analogRead(PIN_POT); // 0–1023
if (currentValue != lastValue) {
Serial.print("Potentiometre A0 = ");
Serial.println(currentValue);
lastValue = currentValue;
}
}