/*
Pilote MOTEUR 2 sens de marche avec 2 relais et 3 bp
Attention ce sketch est pour des relais chinois (logique inverse, HIGH éteint la sortie)
Pour des relais "standart il faut inverser les états (LOW par HIGH)
Les fin de course sont à cablés en "hard"
*/
#define PIN_BOUTON_STOP 7 //Bouton d'arrêt
#define PIN_BOUTON_ANTIHORAIRE 6 //Bouton de marche arrière
#define PIN_BOUTON_HORAIRE 5 //Bouton de marche avant
#define PIN_RELAIS_ANTIHORAIRE 4 //Relais de marche arrière
#define PIN_RELAIS_HORAIRE 3 //Relais de marche avant
void setup() {
pinMode(PIN_BOUTON_STOP, INPUT);
pinMode(PIN_BOUTON_HORAIRE, INPUT);
pinMode(PIN_BOUTON_ANTIHORAIRE, INPUT);
pinMode(PIN_RELAIS_HORAIRE, OUTPUT);
pinMode(PIN_RELAIS_ANTIHORAIRE, OUTPUT);
digitalWrite(PIN_RELAIS_HORAIRE,HIGH); // on initialise le relais marche avant au repos (logique inverse car relais chinois)
digitalWrite(PIN_RELAIS_ANTIHORAIRE,HIGH); // on initialise le relais marche arrière au repos (logique inverse car relais chinois)
}
void loop() {
if(digitalRead(PIN_BOUTON_STOP) == HIGH){ //Lecture état bouton arrêt
stopMoteur(); //Si bouton arrêt appuyé saut vers sous programme (void) stopMoteur
}
if(digitalRead(PIN_BOUTON_HORAIRE) == HIGH){ //Lecture état bouton marche avant
stopMoteur(); //Si bouton marche avantt appuyé saut vers sous programme (void) stopMoteur (on commence par arrèter le moteur)
sensHoraire(); //Ensuite on fait un saut vers sous programme (void) sensHoraire pour la marche avant
delay(500); //On attend une demi seconde
}
if(digitalRead(PIN_BOUTON_ANTIHORAIRE) == HIGH){ //Lecture état bouton marche arrière
stopMoteur(); //Si bouton marche arrière appuyé saut vers sous programme (void) stopMoteur (on commence par arrèter le moteur)
sensAntiHoraire(); //Ensuite on fait un saut vers sous programme (void) sensAntiHoraire pour la marche arrière
delay(500); //On attend une demi seconde
}
}
void sensHoraire(){ //Sous programme (void) sensHoraire
digitalWrite(PIN_RELAIS_ANTIHORAIRE,HIGH); //On stoppe le moteur en marche arrière
delay(500); //On attend une demi seconde
digitalWrite(PIN_RELAIS_HORAIRE,LOW); //On met le moteur en marche avant
}
void sensAntiHoraire(){ //Sous programme (void) sensAntiHoraire
digitalWrite(PIN_RELAIS_HORAIRE,HIGH); //On stoppe le moteur en marche avant
delay(500); //On attend une demi seconde
digitalWrite(PIN_RELAIS_ANTIHORAIRE,LOW); //On met le moteur en marche arrière
}
void stopMoteur(){ //Sous programme (void) stopMoteur
digitalWrite(PIN_RELAIS_HORAIRE,HIGH); //On stoppe le moteur en marche avant
digitalWrite(PIN_RELAIS_ANTIHORAIRE,HIGH); //On stoppe le moteur en marche arrière
delay(1000); //On attend une seconde
}
|