hello
so I'm putting in my code that I wrote for my observatory.
Do you think I can adapt it to the one you gave me?
But unfortunately I wrote it in French
<code>// OUVERTURE TOIT OBSERVATOIRE
// Avec fin de 2 fin de course et une position Parc
// Commande manuel Open,Close et Stop
// commande a distance
const int ledRepos = 3;
const int RelaisOuverture1 = 4;
const int RelaisOuverture2 = 5;
const int RelaisFermeture1 = 6;
const int RelaisFermeture2 = 7;
const int BoutonOpen = A0; //8
const int BoutonClose = A1;
const int BoutonStop = A2;
const int FinOuverture = 12;
const int FinFermeture = 10;
const int Telescope_Parc =2;
const int BoutonRelais =A3;
const int pinRelais =8;
int BoutonOpenState = 0;
int BoutonCloseState = 0;
int FinOuvertureState = 0;
int FinFermetureState = 0;
int Telescope_ParcState = 0;
int BoutonStopState = 0;
bool BoutonRelaisState = LOW; // *****
//les états possible
enum {Repos, Ouverture, Ouvert, Fermeture, Fermer};
int etat = Repos;
bool estAlimente = false; //*****
// le N° des connection et fonction
void setup() {
pinMode(ledRepos, OUTPUT);
pinMode(RelaisOuverture1, OUTPUT);
pinMode(RelaisOuverture2, OUTPUT);
pinMode(RelaisFermeture1, OUTPUT);
pinMode(RelaisFermeture2, OUTPUT);
pinMode(BoutonOpen, INPUT_PULLUP);
pinMode(BoutonClose, INPUT_PULLUP);
pinMode(BoutonStop, INPUT_PULLUP);
pinMode(FinOuverture, INPUT_PULLUP);
pinMode(FinFermeture, INPUT_PULLUP);
pinMode(Telescope_Parc, INPUT_PULLUP);
}// fin setup
void position_toit () { // début des statuts pour le loop
switch (etat) { // début du switch avec les possibilté
case Repos:
digitalWrite(ledRepos, HIGH);
digitalWrite(RelaisOuverture1, LOW);
digitalWrite(RelaisOuverture2, LOW);
digitalWrite(RelaisFermeture1, LOW);
digitalWrite(RelaisFermeture2, LOW);
if (BoutonOpenState == LOW && Telescope_ParcState == LOW ) {
etat = Ouverture;
delay(30);
}
else if(BoutonCloseState == LOW && FinFermetureState == HIGH ){
etat = Fermeture;
delay(30);
}
break;
case Ouverture:
digitalWrite(ledRepos, LOW);
digitalWrite(RelaisOuverture1, HIGH);
digitalWrite(RelaisOuverture2, HIGH);
digitalWrite(RelaisFermeture1, LOW);
digitalWrite(RelaisFermeture2, LOW);
if (FinOuvertureState == LOW) {
etat = Ouvert;
delay(30);
}
else if(Telescope_ParcState == HIGH || BoutonStopState == LOW) {
etat = Repos;
delay(30);
}
break;
case Ouvert:
digitalWrite(ledRepos, HIGH);
digitalWrite(RelaisOuverture1, LOW);
digitalWrite(RelaisOuverture2, LOW);
digitalWrite(RelaisFermeture1, LOW);
digitalWrite(RelaisFermeture2, LOW);
if (BoutonCloseState == LOW && Telescope_ParcState == LOW ) {
etat = Fermeture;
delay(30);
}
break;
case Fermeture:
digitalWrite(ledRepos, LOW);
digitalWrite(RelaisOuverture1, LOW);
digitalWrite(RelaisOuverture2, LOW);
digitalWrite(RelaisFermeture1, HIGH);
digitalWrite(RelaisFermeture2, HIGH);
if (FinFermetureState == LOW) {
etat = Fermer;
delay(30);
}
else if(Telescope_ParcState == HIGH || BoutonStopState == LOW) {
etat = Repos;
delay(30);
}
break;
case Fermer:
digitalWrite(ledRepos, LOW);
digitalWrite(RelaisOuverture1, LOW);
digitalWrite(RelaisOuverture2, LOW);
digitalWrite(RelaisFermeture1, LOW);
digitalWrite(RelaisFermeture2, HIGH);
etat = Repos;
break;
} //fin switch
}// fin void
void loop() {
BoutonRelaisState = digitalRead (BoutonRelais) ;
if (BoutonRelaisState == HIGH) {
estAlimente = !estAlimente; // ****
delay (30);
}
if (estAlimente) {
digitalWrite (pinRelais, HIGH);
// début du programme des fonctions
BoutonOpenState = digitalRead (BoutonOpen) ;
BoutonCloseState = digitalRead (BoutonClose) ;
FinOuvertureState = digitalRead (FinOuverture) ;
FinFermetureState = digitalRead (FinFermeture) ;
Telescope_ParcState = digitalRead (Telescope_Parc);
BoutonStopState = digitalRead (BoutonStop);
position_toit() ;
} else digitalWrite (pinRelais, LOW);
} // fin loop ou programme
</code>