Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #include <Nextion.h>
  2. #include <Servo.h>
  3. #include <EEPROM.h>
  4.  
  5. // Déclarations variables
  6. int consT = 370;
  7. int mesuT= 380;
  8. int consH = 50;
  9. int mesuH= 60;
  10. int modeservomoteur= 0;
  11. int positionservomoteur=45;
  12. int sensservomoteur= 1;
  13. long timerretournement;
  14. long tempretournement=30000;
  15.  
  16. //int radT= 80; //eventuelle sécurité
  17.  
  18. //Déclaration servomoteur
  19. Servo servomoteur;
  20.  
  21. //Déclaration boutons Nexion
  22. NexButton btm = NexButton(1, 2, "btm");
  23. NexButton btp = NexButton(1, 3, "btp");
  24. NexButton bhm = NexButton(1, 4, "bhm");
  25. NexButton bhp = NexButton(1, 5, "bhp");
  26. NexButton bsauvegarde = NexButton(1, 1, "bsauvegarde");
  27.  
  28. //Déclaration evenements tactiles
  29. NexTouch *nex_listen_list[] =
  30. {
  31. &btm, //Bouton
  32. &btp, //Bouton
  33. &bhm,
  34. &bhp,
  35. &bsauvegarde,
  36. NULL
  37. };
  38.  
  39. //Décrementation température
  40. void MoinsTemperature()
  41. {
  42. consT--;
  43. }
  44.  
  45. //Incrementation température
  46. void PlusTemperature()
  47. {
  48. consT++;
  49. }
  50.  
  51. //Décrementation humidité
  52. void MoinsHumidite()
  53. {
  54. consH--;
  55. }
  56.  
  57. //incremendation humidité
  58. void PlusHumidite()
  59. {
  60. consH++;
  61. }
  62.  
  63. //Sauvegarde EEPROM
  64. void sauvegarde()
  65. {/*
  66. EEPROM.put(0,positionservomoteur);
  67. EEPROM.put(1,modeservomoteur);
  68. EEPROM.put(2,consH);
  69. EEPROM.put(4,consT);*/
  70. }
  71.  
  72. void envoistemperature()
  73. {
  74. Serial.print("x2.val=");
  75. Serial.print(mesuT);
  76. Serial.write(0xFF);
  77. Serial.write(0xFF);
  78. Serial.write(0xFF);
  79. }
  80.  
  81. void envoisconstemperature()
  82. {
  83. Serial.print("x0.val=");
  84. Serial.print(consT);
  85. Serial.write(0xFF);
  86. Serial.write(0xFF);
  87. Serial.write(0xFF);
  88. }
  89.  
  90. void envoishumidite()
  91. {
  92. Serial.print("x3.val=");
  93. Serial.print(mesuH);
  94. Serial.write(0xFF);
  95. Serial.write(0xFF);
  96. Serial.write(0xFF);
  97. }
  98.  
  99. void envoisconshumidite()
  100. {
  101. Serial.print("x1.val=");
  102. Serial.print(consH);
  103. Serial.write(0xFF);
  104. Serial.write(0xFF);
  105. Serial.write(0xFF);
  106. }
  107.  
  108. int controleservomoteur()
  109. {
  110. if((sensservomoteur = 1) && (timerretournement) > (tempretournement))
  111. {
  112. for (positionservomoteur = 45; positionservomoteur <= 135; positionservomoteur += 1)
  113. {
  114. servomoteur.write(positionservomoteur);
  115. delay(50);
  116. return (positionservomoteur);
  117. }
  118. }
  119.  
  120.  
  121. if((positionservomoteur = 135) && ((millis() - timerretournement) > (tempretournement)))
  122. {
  123. timerretournement=millis();
  124. sensservomoteur = 2;
  125. return(timerretournement,sensservomoteur,positionservomoteur);
  126. }
  127.  
  128. if((sensservomoteur = 2) && ((millis() - timerretournement) > (tempretournement)))
  129. {
  130. for (positionservomoteur = 135; positionservomoteur >= 45; positionservomoteur -= 1)
  131. {
  132. servomoteur.write(positionservomoteur);
  133. delay(50);
  134. return (positionservomoteur);
  135. }
  136. }
  137.  
  138. if((positionservomoteur = 45) && ((millis() - timerretournement) > (tempretournement)))
  139. {
  140. timerretournement=millis();
  141. sensservomoteur = 1;
  142. return(timerretournement,sensservomoteur,positionservomoteur);
  143. }
  144. }
  145.  
  146.  
  147. void controlechauffage()
  148. {
  149. if(consT> mesuT)
  150. digitalWrite(2,LOW);
  151.  
  152. if(consT< mesuT)
  153. digitalWrite(2,HIGH);
  154. }
  155.  
  156. void controlefogger()
  157. {
  158. if(consH > mesuH)
  159. digitalWrite(3,LOW);
  160.  
  161. if(consH < mesuH)
  162. digitalWrite(3,HIGH);
  163. }
  164.  
  165.  
  166. void setup()
  167. {
  168. // Nexion
  169. Serial.begin(9600); // initialisation communication serie baud 9600
  170. btm.attachPush(MoinsTemperature);
  171. btp.attachPush(PlusTemperature);
  172. bhm.attachPush(MoinsHumidite);
  173. bhp.attachPush(PlusHumidite);
  174. bsauvegarde.attachPush(sauvegarde);
  175.  
  176. //Broches
  177. pinMode (2, OUTPUT); // broche controle chauffage en entrée
  178. pinMode (3,OUTPUT); // broche controle fogger en entrée
  179. //pinMode (4, OUTPUT); // broche controle alimentation servomoteur non utilisée
  180.  
  181. //servomoteur
  182. servomoteur.attach(5);
  183.  
  184. //lecture EEPROM
  185. //EEPROM.get(0,sensservomoteur);
  186. //EEPROM.pget(1,modeservomoteur);
  187. //EEPROM.get(2,consH);
  188. //EEPROM.get(4,consT);
  189.  
  190. //
  191. timerretournement = millis();
  192. //tempretournement = millis();
  193. }
  194.  
  195. void loop()
  196. {
  197. delay(30);
  198. //relevecapteurs();
  199. envoistemperature();
  200. envoisconstemperature();
  201. envoishumidite();
  202. envoisconshumidite();
  203. controleservomoteur();
  204. controlechauffage();
  205. controlefogger();
  206. nexLoop(nex_listen_list);
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement