Advertisement
rikiverga

Untitled

Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.92 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"// definisco il pin del sensore
  6. #define DHTPIN 31// definisco il tipo di sensore
  7. #define DHTTYPE DHT11
  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. int valletto;
  52. float tensione;
  53. int temperatura ;
  54. int umidita ;
  55.  
  56. void setup()
  57. {
  58. Serial.begin(115200);
  59. Serial1.begin(115200);
  60. Serial2.begin(9600);
  61. delay(3000);
  62. if (! rtc.begin()) {
  63. Serial.println("Couldn't find RTC");
  64. while (1);
  65. }
  66.  
  67. if (rtc.lostPower()) {
  68. Serial.println("RTC lost power, lets set the time!");
  69. // following line sets the RTC to the date & time this sketch was compiled
  70. // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  71. // This line sets the RTC with an explicit date & time, for example to set
  72. // January 21, 2014 at 3am you would call:
  73. // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  74. }
  75. nex.init();
  76. pinMode(finecorsa, INPUT_PULLUP);
  77. pinMode(cicalino, OUTPUT);
  78. pinMode(mandrino, OUTPUT);
  79. pinMode(led, OUTPUT);
  80. pinMode(main12v, OUTPUT);
  81. pinMode(ventola, OUTPUT);
  82. digitalWrite(ventola, HIGH);
  83. digitalWrite(main12v, HIGH);
  84. digitalWrite(led, HIGH);
  85. digitalWrite(cicalino, HIGH);
  86. Vorario.setText(bf);
  87. bventola.attachCallback(&callback);
  88. bluce.attachCallback(&callback1);
  89. bSMS.attachCallback(&callback2);
  90. bMain.attachCallback(&callback3);
  91. bcicalino.attachCallback(&callback4);
  92. bmandrino.attachCallback(&callback5);
  93. ModeAUTO.attachCallback(&callback6);
  94. bmute.attachCallback(&callback7);
  95. tm1=millis();
  96. }
  97. void loop() {
  98.  
  99. nex.poll();
  100. valletto = analogRead(Stensione); //This divider module will divide the measured voltage by 5, the maximum voltage it can measure is 25V.
  101. tensione = valletto / 41;
  102.  
  103. if (millis()-tm1>(unsigned long)(3000)){
  104. //Vtemperatura.setValue(temperatura);
  105. //Vumidita.setValue( umidita);
  106. //Vtensione.setValue(tensione);
  107. //Vcorrente.setValue(100);
  108. temperatura = dht.readTemperature();
  109. umidita = dht.readHumidity();
  110. valletto = analogRead(Stensione); //This divider module will divide the measured voltage by 5, the maximum voltage it can measure is 25V.
  111. tensione = valletto / 41;
  112. DateTime now = rtc.now();
  113. sprintf(bf,"%02d/%02d/%d %02d:%02d",now.day(),now.month(), now.year(),now.hour(),now.minute());
  114. Vorario.setText(bf);
  115. tm1=millis();}
  116.  
  117. statofinecorsa = digitalRead(finecorsa);
  118. Serial.print(" selettorecicalino ");
  119. Serial.print(selettorecicalino);
  120. Serial.print(" statoselettoresms ");
  121. Serial.print(statoselettoresms);
  122. Serial.print(" statofinecorsa ");
  123. Serial.print(statofinecorsa);
  124. Serial.print(" ModeAUTO ");
  125. Serial.print(selettoremodeAUTO);
  126. Serial.print(" tempoaggiornamento ");
  127. Serial.print(tempoaggiornamento);
  128. Serial.print(" mute ");
  129. Serial.print(mute);
  130. Serial.print(" timer ");
  131. Serial.println(timer);
  132.  
  133. if (statofinecorsa == HIGH ) { // finecorsa premuto
  134. timer++;
  135. if (timer > tempo ) {
  136. if ( statoselettoresms == 1 && statomessaggio == 0 && selettorecicalino == 0) {
  137. Serial2.println("AT");
  138. delay(500);
  139. Serial2.println("AT+CSCA=\"+393359609600\""); // Centro Messaggi TIM
  140. delay(500);
  141. Serial2.println("AT+CMGF=1\r");
  142. delay(500);
  143. Serial2.println("AT+CMGS=\"+393460399387\"");
  144. delay(500);
  145. Serial2.print("PROGRAMMA FINITO ");
  146. delay(500);
  147. Serial2.println((char)26);
  148. delay(1000);
  149. }
  150. statomessaggio = 1;
  151. timer = 0;
  152. }
  153. }
  154. if ( statofinecorsa == LOW && selettoremodeAUTO == 1) {
  155. statomessaggio = 0;
  156. timer = 0;
  157. digitalWrite(mandrino , HIGH);
  158. mute=0;
  159. }
  160. if ( statofinecorsa == HIGH && selettoremodeAUTO == 1) {
  161. statomessaggio = 0;
  162. timer = 0;
  163. digitalWrite(mandrino , LOW);
  164. }
  165. if (selettorecicalino == 1 && statofinecorsa == HIGH && mute == 0){
  166. if(timer<100 && timer>0){
  167. digitalWrite(cicalino , HIGH);}
  168. if(timer>100 && timer<200){
  169. digitalWrite(cicalino , LOW );}
  170. if(timer>200 && timer<300){
  171. digitalWrite(cicalino , HIGH);}
  172. if(timer>300 && timer<400){
  173. digitalWrite(cicalino , LOW );}
  174. if(timer>400 && timer<500){
  175. digitalWrite(cicalino , HIGH );}
  176. if(timer>500 && timer<600){
  177. digitalWrite(cicalino , LOW );}
  178. if(timer>600 && timer<700){
  179. digitalWrite(cicalino , HIGH );}
  180. if(timer>700 && timer<800){
  181. digitalWrite(cicalino , LOW );}
  182. if(timer>800 && timer<900){
  183. digitalWrite(cicalino , HIGH );}
  184.  
  185. }
  186. if (mute == 1 && selettorecicalino == 1){
  187. digitalWrite(cicalino , LOW );
  188. }
  189. if (mandrinoMAN ==1 ){
  190. digitalWrite(mandrino, HIGH);
  191. }
  192. }
  193.  
  194. void callback(NextionEventType type, INextionTouchable *widget)
  195. {
  196. if (type == NEX_EVENT_POP)
  197. {
  198. if (widget->getNumberProperty("val") == 0)
  199. digitalWrite(ventola, HIGH);
  200. else
  201. digitalWrite(ventola, LOW);
  202. }
  203. }
  204. void callback1(NextionEventType type, INextionTouchable *widget)
  205. {
  206. if (type == NEX_EVENT_POP)
  207. {
  208. if (widget->getNumberProperty("val") == 0)
  209. digitalWrite(led, HIGH);
  210. else
  211. digitalWrite(led, LOW);
  212. }
  213. }
  214. void callback2(NextionEventType type, INextionTouchable *widget)
  215. {
  216. if (type == NEX_EVENT_POP)
  217. {
  218. if (widget->getNumberProperty("val") == 0)
  219. statoselettoresms =0;
  220. else
  221. statoselettoresms =1;
  222. }
  223. }
  224. void callback3(NextionEventType type, INextionTouchable *widget)
  225. {
  226. if (type == NEX_EVENT_POP)
  227. {
  228. if (widget->getNumberProperty("val") == 0)
  229. digitalWrite(main12v, HIGH);
  230. else
  231. digitalWrite(main12v, LOW);
  232. }
  233. }
  234. void callback4(NextionEventType type, INextionTouchable *widget)
  235. {
  236. if (type == NEX_EVENT_POP)
  237. {
  238. if (widget->getNumberProperty("val") == 0)
  239. selettorecicalino=0;
  240. else
  241. selettorecicalino=1;
  242. }
  243. }
  244. void callback5(NextionEventType type, INextionTouchable *widget)
  245. {{if (type == NEX_EVENT_POP)
  246. {
  247. if (widget->getNumberProperty("val") == 0)
  248. mandrinoMAN =0;
  249. else
  250. mandrinoMAN =1;
  251. }
  252. }
  253. }
  254. void callback6(NextionEventType type, INextionTouchable *widget)
  255. {if (type == NEX_EVENT_POP)
  256. {
  257. if (widget->getNumberProperty("val") == 0)
  258. selettoremodeAUTO =0;
  259. else
  260. selettoremodeAUTO =1;
  261. }
  262. }
  263. void callback7(NextionEventType type, INextionTouchable *widget)
  264. {if (type == NEX_EVENT_POP)
  265. {
  266. if (widget->getNumberProperty("val") == 0)
  267. mute=1;
  268.  
  269. }
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement