#include <Arduino.h>
const int btnPin = 15; // Le bouton est connecté à D15
const int ledPin1 = 2; // LED1 sur D2
const int ledPin2 = 4; // LED2 sur D4
#define POTENTIOMETER_PIN 34
void setup() {
pinMode(btnPin, INPUT); // Bouton en entrée
pinMode(ledPin1, OUTPUT); // LED1 en sortie
pinMode(ledPin2, OUTPUT); // LED2 en sortie
analogReadResolution(12);
Serial.begin(115200); // Initialiser la communication série pour les logs
}
void loop() {
int btnState = digitalRead(btnPin); // Lire l'état du bouton
int potValue = analogRead(POTENTIOMETER_PIN);
float voltage = (potValue / 4095.0) * 3.3;
// Si le bouton est pressé, allumer LED1
if (btnState == HIGH) {
digitalWrite(ledPin1, HIGH); // Allumer LED1
} else {
digitalWrite(ledPin1, LOW); // Éteindre LED1
}
// Allumer LED2 en fonction de la position du potentiomètre
if (potValue > 2048) {
digitalWrite(ledPin2, HIGH); // Allumer LED2 si le potentiomètre est au-dessus de 50%
} else {
digitalWrite(ledPin2, LOW); // Éteindre LED2 sinon
}
// Afficher les valeurs sur le moniteur série pour déboguer
Serial.print("Valeur : ");
Serial.print(potValue);
Serial.print(" | Tension : ");
Serial.print(voltage, 3);
Serial.println(" V");
Serial.print("\tBouton : ");
Serial.println(btnState);
delay(100); // Petite pause pour éviter les rebonds du bouton
}