
Sinon à Virieu-le-Grand on avait un PN gardé avec feux clignotants jusqu'en 1992.
Ici à la fin des années 70 un Express Genève - Lyon redémarre de Virieu :
Code : Tout sélectionner
// Dernière mises au point ou modifications
// le 13 octobre 2017 régulation du courant d'alimentation 12v
// le 23 octobre 2017 mise en oeuvre d'un shield 4 relais
// pour coupure de l'alimentation servos (position repos)
// Si besoin des 2 autres relais utilser les PIN 8 & 9 de la carte UNO
// et non 6 & 7 comme prévu dans la notice
// le 8 février 2018 pour réglages des mouvements des barrières
// le 12 février 2018 pour synchronisation des 2 barrières + "a-coups" de verrouillage
#include <Servo.h>
#include <RogueMP3.h>
#include <SoftwareSerial.h>
Servo ServoSud;
Servo ServoNor;
const int DelMvt = 20;
const int PosHauSud = 1950; // plus haut +
const int PosBasSud = 1380; // plus bas -
const int PosHauNor = 1110; // plus haut -
const int PosBasNor = 1580; // plus bas +
byte VolSon = 0; // Volume de la sonnerie (0 = Max, 255 = Min)
int AngSud;
int AngNor;
int LedClg; // Relais 4 du shield 4 relais (Feux clignotants)
int AliSer; // Relais 3 du shield 4 relais (Mise sous tension des servos)
int IndBcl;
boolean FlgPos;
boolean FlgSud;
boolean FlgNor;
boolean FlgBcl;
boolean FlgAff; // On afficehe ... ou pas
SoftwareSerial rogueSerial = SoftwareSerial(6, 7);
RogueMP3 mp3Player = RogueMP3(rogueSerial);
// ICI commence Setup
void setup()
{
// Initialisation lecteur MP3
rogueSerial.begin(9600);
Serial.begin(9600);
if (mp3Player.sync())
{
mp3Player.setVolume(VolSon); // On initialise le volume du MP3
}
else
{
Serial.println("Problème de connexion");
}
// Initialisation relais feux clignotants
LedClg = 4;
AliSer = 5;
pinMode(LedClg, OUTPUT);
pinMode(AliSer, OUTPUT);
// Initialisation des servos barrières
// Et des flags
AngSud = PosBasSud; // position basse
AngNor = PosBasNor; // position basse
ServoSud.attach(3);
ServoNor.attach(2);
ServoSud.writeMicroseconds(AngSud);
ServoNor.writeMicroseconds(AngNor);
FlgPos = LOW;
FlgSud = LOW;
FlgNor = LOW;
FlgBcl = LOW;
FlgAff = HIGH;
delay(800);
digitalWrite(AliSer, HIGH); // mise sous tension des servos
delay(800);
}
// ICI commence Loop
void loop()
{
if (FlgPos == LOW)
{
if (FlgAff == HIGH)
{
// Serial.println("On descend");
FlgAff = LOW;
}
if (AngNor < PosBasNor)
{
AngNor = AngNor + 1;
ServoNor.writeMicroseconds(AngNor);
}
else FlgNor = HIGH;
if (AngSud > PosBasSud)
{
AngSud = AngSud - 1;
ServoSud.writeMicroseconds(AngSud);
}
else FlgSud = HIGH;
delay(DelMvt);
if (FlgSud == HIGH && FlgNor == HIGH)
{
FlgPos = HIGH;
FlgBcl = HIGH;
// "A-coup" pour véroullage en position basse
// Serial.println("Verrouillage BAS");
AngSud = PosBasSud; // position basse
AngNor = PosBasNor; // position basse
ServoSud.writeMicroseconds(AngSud);
ServoNor.writeMicroseconds(AngNor);
ServoSud.detach();
ServoNor.detach();
ServoSud.attach(3);
ServoNor.attach(2);
digitalWrite(AliSer, LOW); // mise hors tension des servos
// Arrêt sonnerie
mp3Player.stop();
FlgAff = HIGH;
// Serial.println("Fin descente");
delay(5000); // attente pour mise au point
AngSud = PosBasSud;
AngNor = PosBasNor;
digitalWrite(AliSer, HIGH); // mise sous tension des servos
}
}
else
{
digitalWrite(LedClg, LOW); // Arrêt clignotants
if (FlgAff == HIGH)
{
Serial.println("On Monte");
FlgAff = LOW;
delay(500);
}
// Rattrapage du décalage des mouvements entre barrières Sud et Nord en montée
if (FlgBcl == HIGH)
for (IndBcl = 0; IndBcl < 13 ; IndBcl++)
{
AngSud = AngSud + 5;
ServoSud.writeMicroseconds(AngSud);
delay(DelMvt);
}
FlgBcl = LOW;
if (AngNor > PosHauNor)
{
AngNor = AngNor - 1;
ServoNor.writeMicroseconds(AngNor);
}
else FlgNor = LOW;
if (AngSud < PosHauSud)
{
AngSud = AngSud + 1;
ServoSud.writeMicroseconds(AngSud);
}
else FlgSud = LOW;
delay(DelMvt);
if (FlgSud == LOW && FlgNor == LOW)
{
FlgPos = LOW;
// "A-coup" pour véroullage en position haute
// Serial.println("Verrouillage HAUT");
AngSud = PosHauSud; // position haute
AngNor = PosHauNor; // position haute
ServoSud.writeMicroseconds(AngSud);
ServoNor.writeMicroseconds(AngNor);
ServoSud.detach();
ServoNor.detach();
ServoSud.attach(3);
ServoNor.attach(2);
digitalWrite(AliSer, LOW); // mise hors tension des servos
FlgAff = HIGH;
// Serial.println("Fin montee");
delay(5000); // Attente pour mise au point
// Déclenchement sonnerie et feux trouges clignotants
mp3Player.playFile("/0001.mp3");
digitalWrite(LedClg, HIGH);
delay(1500);
AngSud = PosHauSud;
AngNor = PosHauNor;
digitalWrite(AliSer, HIGH); // mise sous tension des servos
// Rattrapage du décalage des mouvements entre barrières Sud et Nord en descente
for (IndBcl = 0; IndBcl < 15; IndBcl++)
{
AngSud = AngSud - 5;
// Serial.println("Boucle D");
ServoSud.writeMicroseconds(AngSud);
delay(DelMvt);
}
}
}
}