Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <RTClib.h>
  3. char buffer1[20];
  4. char buffer2[20];
  5. const int setpin = 13;
  6. boolean statepin = 0;
  7. RTC_DS1307 RTC;
  8.  
  9. #include <LiquidCrystal_I2C.h>
  10. LiquidCrystal_I2C lcd(0x27,20,4);
  11.  
  12. #include "DHT.h"
  13. #define DHTPIN 2
  14. #define DHTTYPE DHT22
  15. DHT dht(DHTPIN, DHTTYPE);
  16. float h = dht.readHumidity();
  17. // Read temperature as Celsius (the default)
  18. float t = dht.readTemperature();
  19. float hic = dht.computeHeatIndex(t, h, false);
  20.  
  21.  
  22.  
  23.  
  24. int pulsSU = 3;
  25. int pulsGIU= 4;
  26. int pulsSET =5;
  27. int pulsMENU= 6;
  28.  
  29. int Ton;
  30. int Toff;
  31. int EXIT;
  32. int umidita;
  33. int temperatura;
  34. int minuti;
  35. int ore;
  36. int step_funzione=0;
  37.  
  38. void setup() {
  39. Serial.begin(9600);
  40. Wire.begin();
  41. RTC.begin();
  42. lcd.init();
  43. lcd.backlight();
  44. dht.begin();
  45. pinMode (pulsSU,INPUT);
  46. pinMode (pulsGIU,INPUT);
  47. pinMode (pulsSET,INPUT);
  48. pinMode (pulsMENU,INPUT);
  49. if (! RTC.isrunning()) {
  50. RTC.adjust(DateTime(__DATE__, __TIME__));
  51. }
  52.  
  53.  
  54. }
  55.  
  56. void loop() {
  57.  
  58. statepin = digitalRead (setpin);
  59. if (statepin == LOW)
  60. {
  61. RTC.adjust(DateTime(__DATE__, __TIME__));
  62. }
  63. DateTime now = RTC.now();
  64. sprintf(buffer1, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
  65. //lcd.setCursor(0,0);
  66. //lcd.print( buffer1 );
  67. sprintf(buffer2, "%02d/%02d/%d", now.day(), now.month(), now.year());
  68. //lcd.setCursor(0,1);
  69. //lcd.print( buffer2 );
  70.  
  71. switch (step_funzione) {
  72. case 0: // STATO INIZIALE
  73. INIZIO();
  74. break;
  75. case 1:
  76. set_timeON();
  77.  
  78. break;
  79. case 2:
  80. // set_timeOFF();
  81. break;
  82. // case 3:
  83. // break;
  84. }
  85. }
  86.  
  87.  
  88. void INIZIO (){
  89. t = dht.readTemperature();
  90. h = dht.readHumidity();
  91. lcd.setCursor(6,0);
  92. lcd.print(buffer1);
  93. lcd.setCursor(0,1);
  94. lcd.print("TEMP: C.");
  95. lcd.setCursor(6,1);
  96. lcd.print(t);
  97. lcd.setCursor(0,2);
  98. lcd.print("UMIDITA': %");
  99. lcd.setCursor(9,2);
  100. lcd.print(h);
  101.  
  102.  
  103.  
  104. if(digitalRead(pulsMENU) == HIGH){
  105. delay(1000);
  106. //parte statica
  107. lcd.clear();
  108. lcd.setCursor(2, 0);
  109. lcd.print("SET TIME LIGHT-ON");
  110. step_funzione=1;
  111. }
  112. }
  113. void set_timeON(){
  114. if(digitalRead(pulsSU) == HIGH) {
  115. delay(1);
  116. minuti++;
  117. }
  118. if (minuti>59){
  119. minuti=0;
  120. ore++;}
  121.  
  122. if (ore>23){
  123. ore=0;}
  124.  
  125. lcd.setCursor(7, 2);
  126. if (ore < 10) lcd.print("0"); // SE LE ORE SONO MENO DI 10, SCRIVI LO ZERO A SINISTRA.
  127. lcd.print(ore); // STAMPA LE ORE
  128. lcd.print(":"); // STAMPA I DUE PUNTI
  129. if (minuti < 10) lcd.print("0"); // SE I MINUTI SONO MENO DI 10, SCRIVI LO ZERO A SINISTRA.
  130. lcd.print(minuti);
  131.  
  132. if (digitalRead(pulsSET)==HIGH);{
  133. delay(1000);
  134. lcd.clear();
  135. lcd.setCursor (1,2);
  136. lcd.print("TIME-ON IMPOSTATO");
  137. delay(1000);
  138. step_funzione=2;}
  139.  
  140. if (digitalRead(pulsMENU)==HIGH);{
  141. delay(1000);
  142. lcd.clear();
  143. lcd.setCursor(1,2);
  144. lcd.print("SET-TIME-ON ANNULLATO");
  145. delay(1000);
  146. step_funzione=0;
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement