/*BAL
21/08/2022
Fantasio
Testé sur Nano
si Canton N occupé alors led rouge allumée et envoi info d'occupation vers Canton-1
si Canton N libre et Canton N+1 libre alors led verte allumée
si Canton N libre et Canton N+1 occupé) alors led jaune allumée
par convention:
-une led s'allume si un niveau HIGH est présent en sortie
-si un train occupe un canton le capteur d'occupation voit sa sortie passer du niveau HUGH au niveau LOW
Testé sur Nano
*/
// Constantes
const byte LedRouge = 4; // pin reliée à la led rouge
const byte LedJaune = 3; // pin reliée à la led jaune
const byte LedVerte = 2; // pin reliée à la led verte
const byte OccupationCanton = 10; // pin reliée à l'entrée "OccupationCantonSuivant" du circuit N+1
const byte DetectionTrain = 7; // pin reliée à la sortie du détecteur d'occupation du canton N
const byte OccupationCantonSuivant = 12;// pin reliée à la sortie "OccupationCanton" du canton N-1
// Variable
bool etatLedRouge; // pour la commande d'allumage des leds
bool etatLedJaune;
bool etatLedVerte;
bool etatDetection; // HIGH si Canton N libre, LOW si Canton N occupé
bool etatOccupationCanton; // HIGH si Canton N libre, LOW si Canton N occupé
bool etatOccupationCantonSuivant; // HIGH si Canton N+1 libre, LOW si Canton N+1 occupé
void setup() { // configuration des différentes pins
pinMode(LedRouge, OUTPUT);
pinMode(LedJaune, OUTPUT);
pinMode(LedVerte, OUTPUT);
pinMode(OccupationCanton, OUTPUT);
pinMode(OccupationCantonSuivant, INPUT_PULLUP);
pinMode(DetectionTrain, INPUT_PULLUP);
} // fin setup
void loop() {
etatDetection = digitalRead(DetectionTrain); // lecture de l'état du détecteur d'occupation du canton N
etatOccupationCantonSuivant = digitalRead( OccupationCantonSuivant); // information de l'état d'occupation transmise par le canton N+1
digitalWrite(OccupationCanton, etatOccupationCanton); // on informe le canton N-1 de l'état du canton N
digitalWrite(LedRouge, etatLedRouge);// allumage ou non des leds fonction de leur état respectif
digitalWrite(LedJaune, etatLedJaune);
digitalWrite(LedVerte, etatLedVerte);
if (etatDetection == LOW) { // canton N occupé
etatOccupationCanton = LOW; // information "canton N occupé" à transmettre au canton N-1
etatLedRouge = HIGH; // led rouge allumée
etatLedJaune = LOW; // led jaune éteinte
etatLedVerte = LOW; // led verte éteinte
}
else {
if (etatOccupationCantonSuivant == LOW) { // canton N libre et canton N+1 occupé
etatOccupationCanton = HIGH; // information "canton N libre" à transmettre au canton N-1
etatLedRouge = LOW; // led rouge éteinte
etatLedJaune = HIGH; // led jaune allumée
etatLedVerte = LOW; // led verte éteinte
}
else { // canton N libre et canton N+1 libre
etatOccupationCanton = HIGH; // information "canton N libre" à transmettre au canton N-1
etatLedRouge = LOW; // led rouge éteinte
etatLedJaune = LOW; // led jaune éteinte
etatLedVerte = HIGH; // led verte allumée
}
}
} // fin loop