Advertisement
rikiverga

Untitled

Jul 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3. RTC_DS3231 rtc;
  4. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  5. #include "DHT.h"
  6. #define DHTPIN 30// definisco il pin del sensore
  7. #define DHTTYPE DHT11// definisco il tipo di sensore
  8. DHT dht(DHTPIN, DHTTYPE);
  9. #include <EEPROM.h>
  10. #include <Nextion.h>
  11. #include <NextionPage.h>
  12. #include <NextionDualStateButton.h>
  13. #include <NextionNumber.h>
  14. #include <NextionText.h>
  15. #include <NextionButton.h>
  16. Nextion nex(Serial1);
  17. NextionDualStateButton bMain(nex, 7, 4, "b12v");
  18. NextionDualStateButton bventola(nex, 7, 5, "bventola");
  19. NextionDualStateButton bSMS(nex, 5, 1, "bSMS");
  20. NextionDualStateButton bcicalino(nex, 5, 6, "bcicalino");
  21. NextionDualStateButton ModeAUTO(nex, 5, 5, "bauto");
  22. NextionDualStateButton bluce(nex, 7, 1, "bluce");// DICHUIARAZIONE PULSANTE!!!!!(pagina,id,nome)
  23. NextionDualStateButton bmandrino(nex, 5, 12, "bmandrino");
  24. NextionNumber Vtemperatura(nex, 6, 1, "temperatura");// prova
  25. NextionNumber Vumidita(nex, 6, 3, "umidita");
  26. NextionNumber Vtensione(nex, 6, 5, "tensione");
  27. NextionNumber Vcorrente(nex, 6, 7, "corrente");
  28. NextionText Vorario(nex, 3, 7, "ora");
  29. NextionNumber Vcica(nex, 5, 9, "ncica");
  30. NextionButton bmute(nex, 3, 4, "bmute");
  31. int finecorsa = 22;
  32. int mandrino = 27;
  33. int main12v = 42;//27;
  34. int selettoresms;
  35. int led = 28;
  36. int cicalino = 26;
  37. int ventola = 29;
  38. int statofinecorsa;
  39. int statoselettoresms;
  40. int statomessaggio = 0;
  41. int timer;
  42. int selettorecicalino;
  43. int tempo = 1000;
  44. int Stensione = A0;
  45. char bf[20];
  46. int selettoremodeAUTO;
  47. int tempoaggiornamento;
  48. int mute;
  49. int mandrinoMAN;
  50. unsigned long tm1;
  51. unsigned long tm2;
  52. int valletto;
  53. float tensione;
  54. int temperatura ;
  55. int umidita ;
  56.  
  57. void setup()
  58. {
  59. Serial.begin(115200);
  60. Serial1.begin(115200);
  61. Serial2.begin(9600);
  62. delay(3000);
  63. if (! rtc.begin()) {
  64. Serial.println("Couldn't find RTC");
  65. while (1);
  66. }
  67.  
  68. if (rtc.lostPower()) {
  69. Serial.println("RTC lost power, lets set the time!");
  70. // following line sets the RTC to the date & time this sketch was compiled
  71. // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  72. // This line sets the RTC with an explicit date & time, for example to set
  73. // January 21, 2014 at 3am you would call:
  74. // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  75. }
  76. nex.init();
  77. pinMode(finecorsa, INPUT_PULLUP);
  78. pinMode(cicalino, OUTPUT);
  79. pinMode(mandrino, OUTPUT);
  80. pinMode(led, OUTPUT);
  81. pinMode(main12v, OUTPUT);
  82. pinMode(ventola, OUTPUT);
  83. digitalWrite(ventola, HIGH);
  84. digitalWrite(main12v, HIGH);
  85. digitalWrite(led, HIGH);
  86. digitalWrite(cicalino, HIGH);
  87. Vorario.setText(bf);
  88. bventola.attachCallback(&callback);
  89. bluce.attachCallback(&callback1);
  90. bSMS.attachCallback(&callback2);
  91. bMain.attachCallback(&callback3);
  92. bcicalino.attachCallback(&callback4);
  93. bmandrino.attachCallback(&callback5);
  94. ModeAUTO.attachCallback(&callback6);
  95. bmute.attachCallback(&callback7);
  96. tm1=millis();
  97. tm2=millis();
  98. }
  99. void loop() {
  100.  
  101. nex.poll();
  102. valletto = analogRead(Stensione); //This divider module will divide the measured voltage by 5, the maximum voltage it can measure is 25V.
  103. tensione = valletto / 41;
  104. if (millis()-tm1>(unsigned long)(3000)){
  105. // temperatura = dht.readTemperature();
  106. //umidita = dht.readHumidity();
  107. // Vtemperatura.setValue(temperatura);
  108. //Vumidita.setValue( umidita);
  109. //Vtensione.setValue(tensione);
  110. //Vcorrente.setValue(100);
  111. tm2=millis();
  112. DateTime now = rtc.now();
  113. sprintf(bf,"%02d:%02d",now.hour(),now.minute());
  114. Vorario.setText(bf);
  115. Serial.print("orario");
  116. Serial.println(millis()-tm2);
  117. tm2=millis();
  118. tm1=millis();
  119. }
  120.  
  121. statofinecorsa = digitalRead(finecorsa);
  122. Serial.print(" selettorecicalino ");
  123. Serial.print(selettorecicalino);
  124. Serial.print(" statoselettoresms ");
  125. Serial.print(statoselettoresms);
  126. Serial.print(" statofinecorsa ");
  127. Serial.print(statofinecorsa);
  128. Serial.print(" ModeAUTO ");
  129. Serial.print(selettoremodeAUTO);
  130. Serial.print(" tempoaggiornamento ");
  131. Serial.print(tempoaggiornamento);
  132. Serial.print(" mute ");
  133. Serial.print(mute);
  134. Serial.print(" timer ");
  135. Serial.println(timer);
  136.  
  137. if (statofinecorsa == HIGH ) { // finecorsa premuto
  138. timer++;
  139. if (timer > tempo ) {
  140. if ( statoselettoresms == 1 && statomessaggio == 0 && selettorecicalino == 0) {
  141. Serial2.println("AT");
  142. delay(500);
  143. Serial2.println("AT+CSCA=\"+393359609600\""); // Centro Messaggi TIM
  144. delay(500);
  145. Serial2.println("AT+CMGF=1\r");
  146. delay(500);
  147. Serial2.println("AT+CMGS=\"+393460399387\"");
  148. delay(500);
  149. Serial2.print("PROGRAMMA FINITO ");
  150. delay(500);
  151. Serial2.println((char)26);
  152. delay(1000);
  153. }
  154. statomessaggio = 1;
  155. timer = 0;
  156. }
  157. }
  158. if ( statofinecorsa == LOW && selettoremodeAUTO == 1) {
  159. statomessaggio = 0;
  160. timer = 0;
  161. digitalWrite(mandrino , HIGH);
  162. mute=0;
  163. }
  164. if ( statofinecorsa == HIGH && selettoremodeAUTO == 1) {
  165. statomessaggio = 0;
  166. timer = 0;
  167. digitalWrite(mandrino , LOW);
  168. }
  169. if (selettorecicalino == 1 && statofinecorsa == HIGH && mute == 0){
  170. digitalWrite(cicalino,HIGH);
  171. // NON RIESCO A USARE TONE!!
  172. }
  173.  
  174.  
  175. if (mute == 1 && selettorecicalino == 1){
  176. digitalWrite(cicalino , LOW );
  177. }
  178. if (mandrinoMAN ==1 ){
  179. digitalWrite(mandrino, HIGH);
  180. }
  181. }
  182.  
  183. void callback(NextionEventType type, INextionTouchable *widget)
  184. {
  185. if (type == NEX_EVENT_POP)
  186. {
  187. if (widget->getNumberProperty("val") == 0)
  188. digitalWrite(ventola, HIGH);
  189. else
  190. digitalWrite(ventola, LOW);
  191. }
  192. }
  193. void callback1(NextionEventType type, INextionTouchable *widget)
  194. {
  195. if (type == NEX_EVENT_POP)
  196. {
  197. if (widget->getNumberProperty("val") == 0)
  198. digitalWrite(led, HIGH);
  199. else
  200. digitalWrite(led, LOW);
  201. }
  202. }
  203. void callback2(NextionEventType type, INextionTouchable *widget)
  204. {
  205. if (type == NEX_EVENT_POP)
  206. {
  207. if (widget->getNumberProperty("val") == 0)
  208. statoselettoresms =0;
  209. else
  210. statoselettoresms =1;
  211. }
  212. }
  213. void callback3(NextionEventType type, INextionTouchable *widget)
  214. {
  215. if (type == NEX_EVENT_POP)
  216. {
  217. if (widget->getNumberProperty("val") == 0)
  218. digitalWrite(main12v, HIGH);
  219. else
  220. digitalWrite(main12v, LOW);
  221. }
  222. }
  223. void callback4(NextionEventType type, INextionTouchable *widget)
  224. {
  225. if (type == NEX_EVENT_POP)
  226. {
  227. if (widget->getNumberProperty("val") == 0)
  228. selettorecicalino=0;
  229. else
  230. selettorecicalino=1;
  231. }
  232. }
  233. void callback5(NextionEventType type, INextionTouchable *widget)
  234. {{if (type == NEX_EVENT_POP)
  235. {
  236. if (widget->getNumberProperty("val") == 0)
  237. mandrinoMAN =0;
  238. else
  239. mandrinoMAN =1;
  240. }
  241. }
  242. }
  243. void callback6(NextionEventType type, INextionTouchable *widget)
  244. {if (type == NEX_EVENT_POP)
  245. {
  246. if (widget->getNumberProperty("val") == 0)
  247. selettoremodeAUTO =0;
  248. else
  249. selettoremodeAUTO =1;
  250. }
  251. }
  252. void callback7(NextionEventType type, INextionTouchable *widget)
  253. {if (type == NEX_EVENT_POP)
  254. {
  255. if (widget->getNumberProperty("val") == 0)
  256. mute=1;
  257.  
  258. }
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement