Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <dht11.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <DS1302.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- dht11 DHT11;
- DS1302 rtc(8, 9, 10);
- Time tmi;
- Time tma;
- #define DHT11PIN 2
- //Proměnné a konstanty
- unsigned long previousMillis = 0;
- unsigned long interval = 1000;
- const int buttonPin = 3;
- const int buttonbPin = 4;
- int buttonState = 0;
- int buttonbState = 0;
- int zob = 1;
- int mit;
- int mat;
- int prt;
- int tep;
- int vlh;
- int abc=0;
- int mitt;
- void setup()
- {
- Serial.begin(9600);
- lcd.begin(16,2);
- lcd.Backlight();
- lcd.print("Stanovo mereni senzorem DHT11");
- delay(2500);
- lcd.clear();
- rtc.halt(false);
- rtc.writeProtect(true);
- }
- void loop()
- {
- //cyklus
- unsigned long currentMillis = millis();
- if(currentMillis - previousMillis > interval) {
- previousMillis = currentMillis;
- //---------------------------------------------
- tep = (float)DHT11.temperature, 0;
- vlh = (float)DHT11.humidity, 0;
- //vypocet
- if(mat < tep) {
- mat = tep;
- tma = rtc.getTime();
- }
- if (mit > tep or mit == 0) {
- mit = tep;
- tmi = rtc.getTime();
- }
- prt = (mit + mat)/2;
- lcd.setCursor(0, 0);
- //zobrazení
- if (zob == 2) {
- if (abc == 1) lcd.clear();
- lcd.print("Tep Vlh Prum");
- lcd.setCursor(0, 1);
- lcd.print("C=");
- lcd.print((float)DHT11.temperature, 0);
- lcd.setCursor(5, 1);
- lcd.print("H=");
- lcd.print((float)DHT11.humidity, 0);
- lcd.setCursor(10, 1);
- lcd.print("C=");
- lcd.print(prt);
- }
- if (zob == 1) {
- if (abc == 1) lcd.clear();
- Time t = rtc.getTime();
- if (tmi.hour == 0 and tmi.min == 0 and tmi.sec == 0) {lcd.clear();}
- lcd.setCursor(4, 0);
- lcd.print(rtc.getTimeStr());
- lcd.setCursor(0, 1);
- lcd.print(rtc.getDOWStr(FORMAT_SHORT));
- lcd.setCursor(6, 1);
- lcd.print(rtc.getDateStr());
- }
- if (zob == 3) {
- if (abc == 1) lcd.clear();
- lcd.print("Tep Min Max");
- lcd.setCursor(0, 1);
- lcd.print("C=");
- lcd.print((float)DHT11.temperature, 0);
- lcd.setCursor(5, 1);
- lcd.print("C=");
- lcd.print(mit);
- lcd.setCursor(10, 1);
- lcd.print("C=");
- lcd.print(mat);
- }
- if (zob == 0) {
- if (abc == 1) lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Min teplota");
- lcd.setCursor(0, 1);
- lcd.print("C=");
- lcd.print(mit);
- lcd.setCursor(6, 1);
- lcd.print(tmi.hour, DEC);
- lcd.print(":");
- lcd.print(tmi.min, DEC);
- }
- if (zob == 4) {
- if (abc == 1) lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Max teplota");
- lcd.setCursor(0, 1);
- lcd.print("C=");
- lcd.print(mat);
- lcd.setCursor(6, 1);
- lcd.print(tma.hour, DEC);
- lcd.print(":");
- lcd.print(tma.min, DEC);
- }
- int chk = DHT11.read(DHT11PIN);
- if (buttonState == LOW) {
- abc = 0;
- }
- //delay(500);
- }
- buttonState = digitalRead(buttonPin);
- buttonbState = digitalRead(buttonbPin);
- if (buttonState == HIGH and abc == 0) {
- abc = 1;
- if (zob == 4) {
- zob = 0;
- }
- else {
- zob = zob + 1;
- }
- }
- if (buttonbState == HIGH) {
- //mazání
- mat = tep;
- mit = tep;
- }
- }
Add Comment
Please, Sign In to add comment