// B.A.L avec Arduino - C. BEZANGER - 3 juillet 2026
// -------------------------------------------------
// Les poussoirs sont des I.L.S sur une voie
// Ils delimitent deux cantons
// Le train se deplace de la gauche vers la droite
// Cablage
byte pinILS1 = 2;
byte pinILS2 = 3;
byte pinILS3 = 4;
byte pinVert = 5;
byte pinRouge = 6;
byte pinOrange = 7;
// Variables
boolean etatCant1 = false; // true si occupe
boolean etatCant2 = false; // true si occupe
boolean etatCant3 = false; // true si occupe
void setup() {
// put your setup code here, to run once:
pinMode(pinILS1, INPUT_PULLUP);
pinMode(pinILS2, INPUT_PULLUP);
pinMode(pinILS3, INPUT_PULLUP);
pinMode(pinVert, OUTPUT);
pinMode(pinRouge, OUTPUT);
pinMode(pinOrange, OUTPUT);
digitalWrite(pinVert, HIGH); // au depart, voie libre
digitalWrite(pinRouge, LOW);
digitalWrite(pinOrange, LOW);
}
void loop() {
// Acquisition des donnees
if(digitalRead(pinILS1) == LOW) {
// Train entre Canton 1
etatCant1 = true;
}
if(digitalRead(pinILS2) == LOW) {
// Train quitte Canton 1 et entre Canton 2
etatCant1 = false;
etatCant2 = true;
}
if(digitalRead(pinILS3) == LOW) {
// Train quitte Canton 2 --> voie libre
etatCant2 = false;
}
// Traitement des données
if(etatCant1 == true) {
digitalWrite(pinVert, LOW);
digitalWrite(pinOrange, LOW);
digitalWrite(pinRouge, HIGH);
}
if(etatCant1 == false && etatCant2 == true) {
digitalWrite(pinVert, LOW);
digitalWrite(pinRouge, LOW);
digitalWrite(pinOrange, HIGH);
}
if(etatCant1 == false && etatCant2 == false) {
digitalWrite(pinOrange, LOW);
digitalWrite(pinRouge, LOW);
digitalWrite(pinVert, HIGH);
}
}