SVty

Arduino MHT11 LCD 1602

Apr 11th, 2017
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.35 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <dht11.h>
  3. #include <Wire.h>
  4. #include <LiquidCrystal_I2C.h>
  5. #include <DS1302.h>
  6.  
  7.  
  8. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  9. dht11 DHT11;
  10. DS1302 rtc(8, 9, 10);
  11. Time tmi;
  12. Time tma;
  13.  
  14. #define DHT11PIN 2
  15. //Proměnné a konstanty
  16. unsigned long previousMillis = 0;
  17. unsigned long interval = 1000;
  18. const int buttonPin = 3;
  19. const int buttonbPin = 4;
  20. int buttonState = 0;
  21. int buttonbState = 0;
  22. int zob = 1;
  23. int mit;
  24. int mat;
  25. int prt;
  26. int tep;
  27. int vlh;
  28. int abc=0;
  29. int mitt;
  30.  
  31. void setup()
  32. {
  33.   Serial.begin(9600);
  34.   lcd.begin(16,2);
  35.   lcd.Backlight();
  36.   lcd.print("Stanovo mereni senzorem DHT11");
  37.   delay(2500);
  38.   lcd.clear();
  39.   rtc.halt(false);
  40.   rtc.writeProtect(true);
  41.  
  42. }
  43.  
  44. void loop()
  45. {
  46.   //cyklus
  47.   unsigned long currentMillis = millis();
  48.    
  49.     if(currentMillis - previousMillis > interval) {
  50.  
  51.         previousMillis = currentMillis;
  52.  
  53.   //---------------------------------------------
  54.  
  55.   tep = (float)DHT11.temperature, 0;
  56.   vlh = (float)DHT11.humidity, 0;
  57.   //vypocet
  58.   if(mat < tep) {
  59.     mat = tep;
  60.     tma = rtc.getTime();
  61.   }
  62.   if (mit > tep or mit == 0) {
  63.     mit = tep;
  64.     tmi = rtc.getTime();
  65.   }
  66.   prt = (mit + mat)/2;
  67.  
  68.   lcd.setCursor(0, 0);
  69.   //zobrazení
  70.   if (zob == 2) {
  71.      if (abc == 1) lcd.clear();
  72.      lcd.print("Tep  Vlh  Prum");
  73.      lcd.setCursor(0, 1);
  74.      lcd.print("C=");
  75.      lcd.print((float)DHT11.temperature, 0);
  76.      lcd.setCursor(5, 1);
  77.      lcd.print("H=");
  78.      lcd.print((float)DHT11.humidity, 0);
  79.      lcd.setCursor(10, 1);
  80.      lcd.print("C=");
  81.      lcd.print(prt);
  82.     }
  83.    if (zob == 1) {
  84.       if (abc == 1) lcd.clear();
  85.       Time t = rtc.getTime();
  86.         if (tmi.hour == 0 and tmi.min == 0 and tmi.sec == 0) {lcd.clear();}
  87.       lcd.setCursor(4, 0);
  88.       lcd.print(rtc.getTimeStr());
  89.       lcd.setCursor(0, 1);
  90.       lcd.print(rtc.getDOWStr(FORMAT_SHORT));
  91.       lcd.setCursor(6, 1);
  92.       lcd.print(rtc.getDateStr());
  93.    }
  94.    if (zob == 3) {
  95.      if (abc == 1) lcd.clear();
  96.      lcd.print("Tep  Min   Max");
  97.      lcd.setCursor(0, 1);
  98.      lcd.print("C=");
  99.      lcd.print((float)DHT11.temperature, 0);
  100.      lcd.setCursor(5, 1);
  101.      lcd.print("C=");
  102.      lcd.print(mit);
  103.      lcd.setCursor(10, 1);
  104.      lcd.print("C=");
  105.      lcd.print(mat);
  106.    }
  107.    if (zob == 0) {
  108.       if (abc == 1) lcd.clear();
  109.       lcd.setCursor(0, 0);
  110.       lcd.print("Min teplota");
  111.       lcd.setCursor(0, 1);
  112.       lcd.print("C=");
  113.       lcd.print(mit);
  114.       lcd.setCursor(6, 1);
  115.       lcd.print(tmi.hour, DEC);
  116.       lcd.print(":");
  117.       lcd.print(tmi.min, DEC);
  118.    }
  119.    if (zob == 4) {
  120.       if (abc == 1) lcd.clear();
  121.       lcd.setCursor(0, 0);
  122.       lcd.print("Max teplota");
  123.       lcd.setCursor(0, 1);
  124.       lcd.print("C=");
  125.       lcd.print(mat);
  126.       lcd.setCursor(6, 1);
  127.       lcd.print(tma.hour, DEC);
  128.       lcd.print(":");
  129.       lcd.print(tma.min, DEC);
  130.    }
  131.  
  132.   int chk = DHT11.read(DHT11PIN);
  133.   if (buttonState == LOW) {
  134.   abc = 0;
  135.   }
  136.   //delay(500);
  137. }
  138.   buttonState = digitalRead(buttonPin);
  139.   buttonbState = digitalRead(buttonbPin);
  140.  
  141.   if (buttonState == HIGH and abc == 0) {
  142.     abc = 1;
  143.       if (zob == 4) {
  144.         zob = 0;
  145.       }
  146.       else {
  147.         zob = zob + 1;
  148.       }
  149.   }
  150.  
  151.   if (buttonbState == HIGH) {        
  152.     //mazání
  153.     mat = tep;
  154.     mit = tep;
  155.   }
  156.  
  157. }
Add Comment
Please, Sign In to add comment