kamil004

TinyRTC,LightSensor,LCD16x2,DHT11 (Optional 5110 not finish)

May 27th, 2015
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.51 KB | None | 0 0
  1. #include <DS1307RTC.h>
  2. #include <Time.h>
  3. #include <Wire.h>
  4. #include <DHT.h>
  5. //#include <LCD5110_Graph.h>
  6. #include <LiquidCrystal_I2C.h>
  7.  
  8. #define BACKLIGHT_PIN  3
  9. #define DHTPIN A0
  10. #define DHTTYPE DHT11  
  11.  
  12. LiquidCrystal_I2C  lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE);
  13. //LCD5110 myGLCD(10,9,8,6,7);
  14.  
  15. //extern uint8_t TinyFont [];
  16. //extern uint8_t SmallFont[];    // 5110 nokia
  17. //extern uint8_t MediumNumbers[];   //5110 nokia
  18. //extern uint8_t BigNumbers [];
  19. //extern uint8_t termo[];
  20. //extern uint8_t dwukropek[];
  21.  
  22.     const char *monthName[12] = {
  23.       "01", "02", "03", "04", "05", "06",
  24.       "07", "08", "09", "10", "11", "12"
  25.     };
  26.  
  27. int h;
  28. int t;
  29. //int g;
  30. //int m;
  31. int jasnosc;
  32. tmElements_t tm;
  33. DHT dht(DHTPIN, DHTTYPE);
  34.  
  35. byte temp[8] = //ikona temperatury
  36. {
  37.     B00100,
  38.     B01010,
  39.     B01010,
  40.     B01110,
  41.     B01110,
  42.     B11111,
  43.     B11111,
  44.     B01110
  45. };
  46.  
  47. byte wilg[8] = //ikona wilgotnosci
  48. {
  49.     B00100,
  50.     B00100,
  51.     B01010,
  52.     B10001,
  53.     B10001,
  54.     B10001,
  55.     B01110,
  56. };
  57.  
  58. byte stopnie[8] = //ikona stopni
  59. {
  60.         B01100,
  61.         B10010,
  62.         B10010,
  63.         B01100,
  64.         B00000,
  65.         B00000,
  66.         B00000,
  67.         B00000
  68. };
  69.  
  70. byte procent[8] = //ikona procentu
  71. {
  72.         B00000,
  73.         B11000,
  74.         B11010,
  75.         B00110,
  76.         B01100,
  77.         B01011,
  78.         B00011,
  79.         B00000
  80. };
  81.  
  82.  
  83.  
  84.  
  85. void setup() {
  86.  
  87.    lcd.begin(16, 2);
  88.    lcd.createChar(0, temp);
  89.    lcd.createChar(1, wilg);
  90.    lcd.createChar(3, stopnie);
  91.    lcd.createChar(4, procent);
  92.    dht.begin();
  93. //   myGLCD.InitLCD();
  94.    
  95.    
  96. //   myGLCD.invert(true);
  97.  
  98.  
  99. }
  100.  
  101. void loop() {  
  102. //   myGLCD.setFont(SmallFont);
  103. //   myGLCD.printNumI(h, LEFT, 41);
  104. //   myGLCD.printNumI(t, RIGHT, 41);
  105. //  
  106. //   myGLCD.setFont(MediumNumbers);
  107. //
  108. //   g = (tm.Hour);
  109. //   m = (tm.Minute);
  110. //
  111. //  
  112. //  
  113. //
  114. //
  115. //    if (tm.Hour < 10) {
  116. //     myGLCD.print("0", LEFT, 0);
  117. //     myGLCD.printNumI(tm.Hour, 12, 0);} else
  118. //     myGLCD.printNumI(tm.Hour, LEFT, 0);
  119. //  
  120. //   myGLCD.print("-", 23, 0);
  121. //  
  122. //    if (tm.Minute < 10) {
  123. //     myGLCD.print("0", 34, 0);
  124. //     myGLCD.printNumI(tm.Minute, 46, 0);} else
  125. //     myGLCD.printNumI(tm.Minute, 34, 0);
  126. //    
  127. //   myGLCD.setFont(SmallFont);
  128. //   myGLCD.print(":", 57, 9);  
  129. //  
  130. //   if (tm.Second < 10) {
  131. //    myGLCD.print("0", 62, 9);
  132. //    myGLCD.printNumI(tm.Second, 68, 9);} else
  133. //    myGLCD.printNumI(tm.Second, 62, 9);
  134. //  
  135. //
  136. //  
  137. //   myGLCD.drawBitmap(15, 40, termo, 5, 8);
  138. //   myGLCD.update();
  139.  
  140.   int jasnosc = analogRead(A1);
  141.  {   if (jasnosc <500)
  142.     lcd.setBacklight(1);
  143.     else lcd.setBacklight(0);
  144.  }
  145.  
  146. //  m = tm.Minute();
  147.    
  148.    h = dht.readHumidity();
  149.     lcd.setCursor(12,0);
  150.     lcd.print(h);
  151.     lcd.setCursor(14,0);
  152.     lcd.write(byte(4));
  153.     lcd.setCursor(15,0);
  154.     lcd.write(byte(1));
  155.    
  156.    t = dht.readTemperature();
  157.     lcd.setCursor(12,1);
  158.     lcd.print(t);
  159.     lcd.setCursor(14,1);
  160.     lcd.write(byte(3));
  161.     lcd.setCursor(15,1);
  162.     lcd.write(byte(0));
  163.  
  164.  
  165.  
  166.   if (RTC.read(tm)) {
  167.  
  168.     lcd.setCursor (0, 0);
  169.     LCDprint2digits(tm.Hour);
  170.     lcd.print(':');
  171.     LCDprint2digits(tm.Minute);
  172.     lcd.print(':');
  173.     LCDprint2digits(tm.Second);
  174.     lcd.setCursor (0, 1);
  175.     lcd.print(tm.Day);
  176.     lcd.print('.');
  177.     lcd.print(monthName[tm.Month-1]);
  178.     lcd.print('.');
  179.     lcd.print(tmYearToCalendar(tm.Year));
  180.   }
  181. }
  182.  
  183. void LCDprint2digits(int number) {
  184.   if (number >= 0 && number < 10) {
  185.     lcd.write('0');
  186.   }
  187.   lcd.print(number);  
  188. }
Advertisement
Add Comment
Please, Sign In to add comment