#define PIN_POT A0 // Broche du potentiomètre
#define PIN_LED A5 // Broche de la LED
const unsigned long INTERVAL = 50; // Intervalle de lecture (ms)
const int THRESHOLD = 500; // Seuil pour allumer la LED
int lastValue = -1; // Valeur précédente du pot.
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600); // Initialisation du port série
pinMode(PIN_LED, OUTPUT); // LED en sortie
digitalWrite(PIN_LED, LOW); // Éteinte par défaut
}
void loop() {
unsigned long now = millis();
if (now - lastMillis < INTERVAL) {
return; // Attente du prochain intervalle
}
lastMillis = now;
int currentValue = analogRead(PIN_POT); // Lecture 0–1023
// Affichage seulement en cas de changement
if (currentValue != lastValue) {
Serial.print("Potentiometre A0 = ");
Serial.println(currentValue);
lastValue = currentValue;
}
// Allumage/extinction de la LED selon le seuil
if (currentValue > THRESHOLD) {
digitalWrite(PIN_LED, HIGH);
} else {
digitalWrite(PIN_LED, LOW);
}
}