Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <LiquidCrystal.h>
  4. #include <DS1302.h>
  5. #include <TimeLib.h>
  6. #define ONE_WIRE_BUS 12
  7. OneWire oneWire(ONE_WIRE_BUS);
  8.  
  9. //Przekazanie danych z biblioteki oneWire do DallasTemperature
  10. DallasTemperature sensors(&oneWire);
  11.  
  12. // Definicja pinów wyświetlacza
  13. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  14.  
  15. //Deklaracja pinów guzików
  16. const int buttonPin = A0;
  17. const int buttonPin2 = A1;
  18. const int buttonPin3 = A2;
  19.  
  20. //Deklaracja pinu alarmu
  21. const int ledPin = 13;
  22.  
  23. //Deklaracja Relay'a
  24. const int in1 = 11;
  25.  
  26. //Deklaracja zegara RTC
  27. //Input output
  28. int RTC_IO = 8;
  29. //Serial Clock
  30. int RTC_SC = 9;
  31. //Chip Enable
  32. int RTC_CE = 10;
  33. // ce io sc
  34.  
  35. DS1302 rtc(RTC_CE, RTC_IO, RTC_SC);
  36.  
  37. //Deklaracja zmiennych "bool", stanowią o stanie guzika
  38. int buttonState = 0;
  39. int buttonState2 = 0;
  40. int buttonState3 = 0;
  41.  
  42. //Deklaracja zmiennej sterującej menu
  43. int start = 0;
  44.  
  45. //Deklaracja kontroli trybu dnia
  46. int zmiana = 1;
  47.  
  48. //RTC Zmienna przechowująca godzine
  49. int RTC_currentHour;
  50.  
  51. //Deklaracja zmiennej o zmianie ogrzewania
  52. bool CzyZmieniac = true;
  53.  
  54. void setup(void)
  55. {
  56. //Inicjacja czujnika
  57. sensors.begin();
  58. //Inicjacja wyświetlacza
  59. lcd.begin(16, 2);
  60. lcd.clear();
  61.  
  62. //Deklaracja wejść(guzików) oraz alarmu(LED)
  63. pinMode(ledPin, OUTPUT);
  64.  
  65. pinMode(buttonPin, INPUT);
  66. digitalWrite(buttonPin, HIGH);
  67.  
  68. pinMode(buttonPin2, INPUT);
  69. digitalWrite(buttonPin2, HIGH);
  70.  
  71. pinMode(buttonPin3, INPUT);
  72. digitalWrite(buttonPin3, HIGH);
  73.  
  74. //Relay
  75. pinMode(in1, OUTPUT);
  76. digitalWrite(in1, HIGH);
  77.  
  78. //RTC
  79. Serial.begin(9600);
  80. rtc.halt(false);
  81. rtc.writeProtect(false);
  82.  
  83. }
  84.  
  85. void loop(void){
  86. //Pobieranie obecnej godziny
  87. RTC_currentHour = rtc.getTime().hour;
  88.  
  89. //Nadpisanie Trybu zależnego od godziny
  90. if(RTC_currentHour >= 20 && RTC_currentHour <= 6){
  91. if(CzyZmieniac){
  92. zmiana = 0;
  93. }
  94. }
  95. else
  96. {
  97. zmiana = 1;
  98. }
  99.  
  100.  
  101. //Wyświetlenie stałego napisu
  102. lcd.setCursor(0, 0);
  103. lcd.print("Temperatura:");
  104.  
  105. //Pobranie wartości temperatury
  106. sensors.requestTemperatures();
  107.  
  108. //*********************OBSŁUGA DANYCH TEMPERATUR DZIEN ***************
  109. if(zmiana == 1){
  110. if(start == 0){
  111. lcd.setCursor(0, 1);
  112. lcd.print(sensors.getTempCByIndex(0));
  113. lcd.setCursor(6, 1);
  114. lcd.print("stopni C");
  115. if(sensors.getTempCByIndex(0)>25){
  116.  
  117. wylaczGrzalke();
  118. }
  119. else if(sensors.getTempCByIndex(0)<20)
  120. {
  121. wlaczGrzalke();
  122. }
  123.  
  124. }//Koniec if (start == 0)
  125.  
  126. if(start == 1){
  127. lcd.setCursor(0, 1);
  128.  
  129. if(sensors.getTempCByIndex(0)>25 && sensors.getTempCByIndex(0)<35){
  130. lcd.setCursor(0, 1);
  131. lcd.print("Odpowiednia");
  132.  
  133. wylaczGrzalke();
  134.  
  135. }
  136. else if (sensors.getTempCByIndex(0)<25)
  137. {
  138. lcd.setCursor(0, 1);
  139. lcd.print("Zbyt niska ");
  140. if(sensors.getTempCByIndex(0)<20){
  141. wlaczGrzalke();
  142. }
  143. }
  144. else if (sensors.getTempCByIndex(0)>35){
  145. lcd.setCursor(0, 1);
  146. lcd.print("Zbyt wysoka ");
  147. }
  148. }//Koniec if (start == 1)
  149.  
  150. //Kontrola LED(Alarm)
  151. if(sensors.getTempCByIndex(0)>35){
  152. digitalWrite(ledPin, HIGH);
  153. }
  154. else
  155. {
  156. digitalWrite(ledPin, LOW);
  157. }
  158. }//Zakonczenie ogolnego IF (Tryb dnia)
  159. //*********************OBSŁUGA DANYCH TEMPERATUR DZIEN ***************
  160.  
  161. //*********************OBSŁUGA DANYCH TEMPERATUR NOC *****************
  162. if(zmiana == 0){
  163. if(start == 0){
  164. lcd.setCursor(0, 1);
  165. lcd.print(sensors.getTempCByIndex(0));
  166. lcd.setCursor(6, 1);
  167. lcd.print("stopni C");
  168. if(sensors.getTempCByIndex(0)>20){
  169.  
  170. wylaczGrzalke();
  171. }
  172. else if(sensors.getTempCByIndex(0)<20)
  173. {
  174. if(sensors.getTempCByIndex(0)<17){
  175. wlaczGrzalke();
  176. }
  177. }
  178.  
  179. }//Koniec if (start == 0)
  180.  
  181. if(start == 1){
  182. lcd.setCursor(0, 1);
  183.  
  184. if(sensors.getTempCByIndex(0)>20 && sensors.getTempCByIndex(0)<35){
  185. lcd.setCursor(0, 1);
  186. lcd.print("Odpowiednia");
  187.  
  188. wylaczGrzalke();
  189.  
  190. }
  191. else if (sensors.getTempCByIndex(0)<20)
  192. {
  193. lcd.setCursor(0, 1);
  194. lcd.print("Zbyt niska ");
  195.  
  196. if(sensors.getTempCByIndex(0)<17){
  197. wlaczGrzalke();
  198. }
  199. }
  200. else if (sensors.getTempCByIndex(0)>35){
  201. lcd.setCursor(0, 1);
  202. lcd.print("Zbyt wysoka ");
  203. }
  204. }//Koniec if (start == 1)
  205.  
  206. //Kontrola LED(Alarm)
  207. if(sensors.getTempCByIndex(0)>35){
  208. digitalWrite(ledPin, HIGH);
  209. }
  210. else
  211. {
  212. digitalWrite(ledPin, LOW);
  213. }
  214. }//Zakonczenie ogolnego IF (Tryb nocy)
  215. //*********************OBSŁUGA DANYCH TEMPERATUR NOC *****************
  216.  
  217. // *****************************PRZYCISKI *********************
  218. buttonState = digitalRead(buttonPin);
  219. if(buttonState == HIGH){
  220.  
  221. lcd.clear();
  222. start = 0;
  223.  
  224. }//Koniec button1
  225.  
  226. //Zaleznie od buttona 2
  227. buttonState2 = digitalRead(buttonPin2);
  228. if(buttonState2 == HIGH){
  229.  
  230. lcd.clear();
  231. start = 1;
  232.  
  233. }//Koniec buttona 2
  234.  
  235. buttonState3 = digitalRead(buttonPin3);
  236. if(buttonState3 == HIGH){
  237.  
  238. start = 2;
  239. lcd.clear();
  240. lcd.setCursor(0, 0);
  241. lcd.write("Zmieniono tryb :");
  242. lcd.setCursor(0, 1);
  243.  
  244. if(CzyZmieniac == true){
  245. CzyZmieniac = false;
  246. }
  247. else{
  248. CzyZmieniac = true;
  249. }
  250.  
  251. if(CzyZmieniac == true){
  252. lcd.write("Obecny - RTC");
  253. }
  254. else if(CzyZmieniac == false) {
  255. lcd.write("Obecny - NONE");
  256. }
  257.  
  258.  
  259. delay(1500);
  260. lcd.clear();
  261. start = 0;
  262. }//Koniec buttona 3
  263.  
  264. // **********************PRZYCISKI *********************
  265.  
  266. }//Zakończenie Loop'a
  267.  
  268. void wlaczGrzalke(){
  269. //Relay
  270. digitalWrite(in1, LOW);
  271. }
  272.  
  273. void wylaczGrzalke(){
  274. digitalWrite(in1, HIGH);
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement