// Définir les broches
const int ledPinRouge = 2;
const int ledPinBleu = 4;
const int ledPinVert = 16;
const int buttonPin1 = 22;
const int buttonPin2 = 23;
// Pour le clignotement
unsigned long previousMillis = 0;
const long interval = 500;
bool ledBlancheClignote = false;
void setup() {
pinMode(ledPinRouge, OUTPUT);
pinMode(ledPinBleu, OUTPUT);
pinMode(ledPinVert, OUTPUT);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
}
void loop() {
// Lire l'état des boutons
bool button1 = digitalRead(buttonPin1);
bool button2 = digitalRead(buttonPin2);
if (button1 == HIGH) {
// Bouton 1 relâché → LED rouge ON, autres OFF
digitalWrite(ledPinRouge, HIGH);
digitalWrite(ledPinBleu, LOW);
digitalWrite(ledPinVert, LOW);
}
else if (button1 == LOW && button2 == LOW) {
// Bouton 1 ET 2 appuyés → clignotement LED blanche (R+G+B)
if (millis() - previousMillis >= interval) {
previousMillis = millis();
ledBlancheClignote = !ledBlancheClignote;
int state = ledBlancheClignote ? HIGH : LOW;
digitalWrite(ledPinRouge, state);
digitalWrite(ledPinBleu, state);
digitalWrite(ledPinVert, state);
}
}
else if (button1 == LOW && button2 == HIGH) {
// Bouton 1 seul appuyé → LED bleue ON, autres OFF
digitalWrite(ledPinRouge, LOW);
digitalWrite(ledPinBleu, HIGH);
digitalWrite(ledPinVert, LOW);
}
}