Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Nextion.h>
- #include <Servo.h>
- #include <EEPROM.h>
- // Déclarations variables
- int consT = 370;
- int mesuT= 380;
- int consH = 50;
- int mesuH= 60;
- int modeservomoteur= 0;
- int positionservomoteur=45;
- int sensservomoteur= 1;
- long timerretournement;
- long tempretournement=30000;
- //int radT= 80; //eventuelle sécurité
- //Déclaration servomoteur
- Servo servomoteur;
- //Déclaration boutons Nexion
- NexButton btm = NexButton(1, 2, "btm");
- NexButton btp = NexButton(1, 3, "btp");
- NexButton bhm = NexButton(1, 4, "bhm");
- NexButton bhp = NexButton(1, 5, "bhp");
- NexButton bsauvegarde = NexButton(1, 1, "bsauvegarde");
- //Déclaration evenements tactiles
- NexTouch *nex_listen_list[] =
- {
- &btm, //Bouton
- &btp, //Bouton
- &bhm,
- &bhp,
- &bsauvegarde,
- NULL
- };
- //Décrementation température
- void MoinsTemperature()
- {
- consT--;
- }
- //Incrementation température
- void PlusTemperature()
- {
- consT++;
- }
- //Décrementation humidité
- void MoinsHumidite()
- {
- consH--;
- }
- //incremendation humidité
- void PlusHumidite()
- {
- consH++;
- }
- //Sauvegarde EEPROM
- void sauvegarde()
- {/*
- EEPROM.put(0,positionservomoteur);
- EEPROM.put(1,modeservomoteur);
- EEPROM.put(2,consH);
- EEPROM.put(4,consT);*/
- }
- void envoistemperature()
- {
- Serial.print("x2.val=");
- Serial.print(mesuT);
- Serial.write(0xFF);
- Serial.write(0xFF);
- Serial.write(0xFF);
- }
- void envoisconstemperature()
- {
- Serial.print("x0.val=");
- Serial.print(consT);
- Serial.write(0xFF);
- Serial.write(0xFF);
- Serial.write(0xFF);
- }
- void envoishumidite()
- {
- Serial.print("x3.val=");
- Serial.print(mesuH);
- Serial.write(0xFF);
- Serial.write(0xFF);
- Serial.write(0xFF);
- }
- void envoisconshumidite()
- {
- Serial.print("x1.val=");
- Serial.print(consH);
- Serial.write(0xFF);
- Serial.write(0xFF);
- Serial.write(0xFF);
- }
- int controleservomoteur()
- {
- if((sensservomoteur = 1) && (timerretournement) > (tempretournement))
- {
- for (positionservomoteur = 45; positionservomoteur <= 135; positionservomoteur += 1)
- {
- servomoteur.write(positionservomoteur);
- delay(50);
- return (positionservomoteur);
- }
- }
- if((positionservomoteur = 135) && ((millis() - timerretournement) > (tempretournement)))
- {
- timerretournement=millis();
- sensservomoteur = 2;
- return(timerretournement,sensservomoteur,positionservomoteur);
- }
- if((sensservomoteur = 2) && ((millis() - timerretournement) > (tempretournement)))
- {
- for (positionservomoteur = 135; positionservomoteur >= 45; positionservomoteur -= 1)
- {
- servomoteur.write(positionservomoteur);
- delay(50);
- return (positionservomoteur);
- }
- }
- if((positionservomoteur = 45) && ((millis() - timerretournement) > (tempretournement)))
- {
- timerretournement=millis();
- sensservomoteur = 1;
- return(timerretournement,sensservomoteur,positionservomoteur);
- }
- }
- void controlechauffage()
- {
- if(consT> mesuT)
- digitalWrite(2,LOW);
- if(consT< mesuT)
- digitalWrite(2,HIGH);
- }
- void controlefogger()
- {
- if(consH > mesuH)
- digitalWrite(3,LOW);
- if(consH < mesuH)
- digitalWrite(3,HIGH);
- }
- void setup()
- {
- // Nexion
- Serial.begin(9600); // initialisation communication serie baud 9600
- btm.attachPush(MoinsTemperature);
- btp.attachPush(PlusTemperature);
- bhm.attachPush(MoinsHumidite);
- bhp.attachPush(PlusHumidite);
- bsauvegarde.attachPush(sauvegarde);
- //Broches
- pinMode (2, OUTPUT); // broche controle chauffage en entrée
- pinMode (3,OUTPUT); // broche controle fogger en entrée
- //pinMode (4, OUTPUT); // broche controle alimentation servomoteur non utilisée
- //servomoteur
- servomoteur.attach(5);
- //lecture EEPROM
- //EEPROM.get(0,sensservomoteur);
- //EEPROM.pget(1,modeservomoteur);
- //EEPROM.get(2,consH);
- //EEPROM.get(4,consT);
- //
- timerretournement = millis();
- //tempretournement = millis();
- }
- void loop()
- {
- delay(30);
- //relevecapteurs();
- envoistemperature();
- envoisconstemperature();
- envoishumidite();
- envoisconshumidite();
- controleservomoteur();
- controlechauffage();
- controlefogger();
- nexLoop(nex_listen_list);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement