Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <LiquidCrystal.h>
- #include <DS1302.h>
- #include <TimeLib.h>
- #define ONE_WIRE_BUS 12
- OneWire oneWire(ONE_WIRE_BUS);
- //Przekazanie danych z biblioteki oneWire do DallasTemperature
- DallasTemperature sensors(&oneWire);
- // Definicja pinów wyświetlacza
- LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
- //Deklaracja pinów guzików
- const int buttonPin = A0;
- const int buttonPin2 = A1;
- const int buttonPin3 = A2;
- //Deklaracja pinu alarmu
- const int ledPin = 13;
- //Deklaracja Relay'a
- const int in1 = 11;
- //Deklaracja zegara RTC
- //Input output
- int RTC_IO = 8;
- //Serial Clock
- int RTC_SC = 9;
- //Chip Enable
- int RTC_CE = 10;
- // ce io sc
- DS1302 rtc(RTC_CE, RTC_IO, RTC_SC);
- //Deklaracja zmiennych "bool", stanowią o stanie guzika
- int buttonState = 0;
- int buttonState2 = 0;
- int buttonState3 = 0;
- //Deklaracja zmiennej sterującej menu
- int start = 0;
- //Deklaracja kontroli trybu dnia
- int zmiana = 1;
- //RTC Zmienna przechowująca godzine
- int RTC_currentHour;
- //Deklaracja zmiennej o zmianie ogrzewania
- bool CzyZmieniac = true;
- void setup(void)
- {
- //Inicjacja czujnika
- sensors.begin();
- //Inicjacja wyświetlacza
- lcd.begin(16, 2);
- lcd.clear();
- //Deklaracja wejść(guzików) oraz alarmu(LED)
- pinMode(ledPin, OUTPUT);
- pinMode(buttonPin, INPUT);
- digitalWrite(buttonPin, HIGH);
- pinMode(buttonPin2, INPUT);
- digitalWrite(buttonPin2, HIGH);
- pinMode(buttonPin3, INPUT);
- digitalWrite(buttonPin3, HIGH);
- //Relay
- pinMode(in1, OUTPUT);
- digitalWrite(in1, HIGH);
- //RTC
- Serial.begin(9600);
- rtc.halt(false);
- rtc.writeProtect(false);
- }
- void loop(void){
- //Pobieranie obecnej godziny
- RTC_currentHour = rtc.getTime().hour;
- //Nadpisanie Trybu zależnego od godziny
- if(RTC_currentHour >= 20 && RTC_currentHour <= 6){
- if(CzyZmieniac){
- zmiana = 0;
- }
- }
- else
- {
- zmiana = 1;
- }
- //Wyświetlenie stałego napisu
- lcd.setCursor(0, 0);
- lcd.print("Temperatura:");
- //Pobranie wartości temperatury
- sensors.requestTemperatures();
- //*********************OBSŁUGA DANYCH TEMPERATUR DZIEN ***************
- if(zmiana == 1){
- if(start == 0){
- lcd.setCursor(0, 1);
- lcd.print(sensors.getTempCByIndex(0));
- lcd.setCursor(6, 1);
- lcd.print("stopni C");
- if(sensors.getTempCByIndex(0)>25){
- wylaczGrzalke();
- }
- else if(sensors.getTempCByIndex(0)<20)
- {
- wlaczGrzalke();
- }
- }//Koniec if (start == 0)
- if(start == 1){
- lcd.setCursor(0, 1);
- if(sensors.getTempCByIndex(0)>25 && sensors.getTempCByIndex(0)<35){
- lcd.setCursor(0, 1);
- lcd.print("Odpowiednia");
- wylaczGrzalke();
- }
- else if (sensors.getTempCByIndex(0)<25)
- {
- lcd.setCursor(0, 1);
- lcd.print("Zbyt niska ");
- if(sensors.getTempCByIndex(0)<20){
- wlaczGrzalke();
- }
- }
- else if (sensors.getTempCByIndex(0)>35){
- lcd.setCursor(0, 1);
- lcd.print("Zbyt wysoka ");
- }
- }//Koniec if (start == 1)
- //Kontrola LED(Alarm)
- if(sensors.getTempCByIndex(0)>35){
- digitalWrite(ledPin, HIGH);
- }
- else
- {
- digitalWrite(ledPin, LOW);
- }
- }//Zakonczenie ogolnego IF (Tryb dnia)
- //*********************OBSŁUGA DANYCH TEMPERATUR DZIEN ***************
- //*********************OBSŁUGA DANYCH TEMPERATUR NOC *****************
- if(zmiana == 0){
- if(start == 0){
- lcd.setCursor(0, 1);
- lcd.print(sensors.getTempCByIndex(0));
- lcd.setCursor(6, 1);
- lcd.print("stopni C");
- if(sensors.getTempCByIndex(0)>20){
- wylaczGrzalke();
- }
- else if(sensors.getTempCByIndex(0)<20)
- {
- if(sensors.getTempCByIndex(0)<17){
- wlaczGrzalke();
- }
- }
- }//Koniec if (start == 0)
- if(start == 1){
- lcd.setCursor(0, 1);
- if(sensors.getTempCByIndex(0)>20 && sensors.getTempCByIndex(0)<35){
- lcd.setCursor(0, 1);
- lcd.print("Odpowiednia");
- wylaczGrzalke();
- }
- else if (sensors.getTempCByIndex(0)<20)
- {
- lcd.setCursor(0, 1);
- lcd.print("Zbyt niska ");
- if(sensors.getTempCByIndex(0)<17){
- wlaczGrzalke();
- }
- }
- else if (sensors.getTempCByIndex(0)>35){
- lcd.setCursor(0, 1);
- lcd.print("Zbyt wysoka ");
- }
- }//Koniec if (start == 1)
- //Kontrola LED(Alarm)
- if(sensors.getTempCByIndex(0)>35){
- digitalWrite(ledPin, HIGH);
- }
- else
- {
- digitalWrite(ledPin, LOW);
- }
- }//Zakonczenie ogolnego IF (Tryb nocy)
- //*********************OBSŁUGA DANYCH TEMPERATUR NOC *****************
- // *****************************PRZYCISKI *********************
- buttonState = digitalRead(buttonPin);
- if(buttonState == HIGH){
- lcd.clear();
- start = 0;
- }//Koniec button1
- //Zaleznie od buttona 2
- buttonState2 = digitalRead(buttonPin2);
- if(buttonState2 == HIGH){
- lcd.clear();
- start = 1;
- }//Koniec buttona 2
- buttonState3 = digitalRead(buttonPin3);
- if(buttonState3 == HIGH){
- start = 2;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.write("Zmieniono tryb :");
- lcd.setCursor(0, 1);
- if(CzyZmieniac == true){
- CzyZmieniac = false;
- }
- else{
- CzyZmieniac = true;
- }
- if(CzyZmieniac == true){
- lcd.write("Obecny - RTC");
- }
- else if(CzyZmieniac == false) {
- lcd.write("Obecny - NONE");
- }
- delay(1500);
- lcd.clear();
- start = 0;
- }//Koniec buttona 3
- // **********************PRZYCISKI *********************
- }//Zakończenie Loop'a
- void wlaczGrzalke(){
- //Relay
- digitalWrite(in1, LOW);
- }
- void wylaczGrzalke(){
- digitalWrite(in1, HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement