Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*****************************************************************PASSAGE A NIVEAU************************************************************************************
- //*********************************************************************************************************************************************************************
- //Un bouton poussoir pour fermer le passage, Un autre bouton poussoir pour l'ouvrir avec chacun une led pour signaler l'etat du passage (mode manuel)
- //Un capteur de distance pour la fermeture (mode automatique)
- //Un capteur de distance pour l'ouverture (mode automatique)
- //Un interrupteur pour basculer du mode automatique au mode manuel
- //Deux servomoteurs pour les barriéres
- //Le passage a niveau est ouvert au demarrage du programme
- //*********************************************************************************************************************************************************************
- #include <Servo.h> //bibliotéque servomoteur
- int bouton1 = 3; //bouton fermeture passage a niveau
- int bouton2 = 2; //bouton ouverture passage a niveau
- int etatbouton1 = 0;
- int etatbouton2 = 0;
- bool boutonState = false;
- int Led1 = 6; //led fermeture passage a niveau
- int Led2 = 7; //led ouverture passage a niveau
- int Led3 = 4; //led signaux passage a niveau
- #define Broche_Echo 12
- #define Broche_Trigger 11
- int MesureMaxi = 300;
- int MesureMini = 3;
- long Duree;
- long Distance;
- int AutoManuel = 8;
- Servo monservo; //servomoteur barriéres
- void setup(){
- Serial.begin(115200);
- pinMode(bouton1, INPUT); //bouton fermeture passage a niveau
- pinMode(bouton2, INPUT); //bouton ouverture passage a niveau
- pinMode(AutoManuel, INPUT);
- pinMode(Broche_Trigger, OUTPUT);
- pinMode(Broche_Echo, INPUT);
- pinMode(Led1, OUTPUT); //led fermeture passage a niveau
- pinMode(Led2, OUTPUT); //led ouverture passage a niveau
- pinMode(Led3, OUTPUT); //led signaux passage a niveau
- digitalWrite(Led2, HIGH); //led ouverture passage a niveau
- monservo.attach(5); //servomoteur barriéres
- }
- void loop()
- {
- //*****************************MANUEL****************************************************
- if(digitalRead(AutoManuel) == HIGH && !boutonState)
- {
- etatbouton1 = digitalRead (bouton1);
- etatbouton2 = digitalRead (bouton2);
- if (etatbouton1==HIGH) {
- digitalWrite(Led1, HIGH);
- digitalWrite(Led2, LOW);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- monservo.write (0);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- }
- if (etatbouton2==HIGH) {
- digitalWrite(Led1, LOW);
- digitalWrite(Led2, HIGH);
- digitalWrite(Led3, LOW);
- monservo.write (90);
- boutonState = !boutonState;
- delay(500);
- }
- }
- //*******************************AUTOMATIQUE**********************************************
- if(digitalRead(AutoManuel) == HIGH && boutonState)
- {
- digitalWrite(Broche_Trigger, LOW);
- delayMicroseconds(2);
- digitalWrite(Broche_Trigger, HIGH);
- delayMicroseconds(10);
- digitalWrite(Broche_Trigger, LOW);
- Duree = pulseIn(Broche_Echo, HIGH);
- Distance = Duree*0.034/2;
- if (Distance >= MesureMaxi || Distance <= MesureMini) {
- digitalWrite(Led1, HIGH);
- digitalWrite(Led2, LOW);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- monservo.write (0);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- delay(800);
- digitalWrite(Led3, LOW);
- delay(800);
- digitalWrite(Led3, HIGH);
- Serial.println("fermer");
- }
- else
- {
- digitalWrite(Led1, LOW);
- digitalWrite(Led2, HIGH);
- digitalWrite(Led3, LOW);
- monservo.write (90);
- Serial.println("ouvert");
- boutonState = !boutonState;
- delay(500);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement