Advertisement
Guest User

nextion_arduino_rtc_ds1308_dht22

a guest
Apr 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <Nextion.h>
  3. #include <TimeLib.h>
  4. #include <DS1307RTC.h>
  5. #include <Wire.h>
  6. #include <DHT.h>
  7. #include <DHT_U.h>
  8. #define DHTPIN 6
  9. #define DHTTYPE DHT22
  10. DHT_Unified dht(DHTPIN, DHTTYPE);
  11. uint32_t delayMS;
  12. int light;
  13. const int led2 = 13;
  14.  
  15.  
  16. SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino
  17.  
  18. Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps
  19.  
  20. void setup() {
  21. Serial.begin(9600);
  22. dht.begin();
  23. myNextion.init();
  24. pinMode(light,INPUT);
  25. pinMode(13,OUTPUT);
  26.  
  27. }
  28. void loop() {
  29. digitalWrite(13, LOW);
  30. int light = "HIGH";
  31. int value= digitalRead(light);
  32. int brightness = (value);
  33. int bright = map(brightness, 0, 1, 5, 90);
  34. String dim = "dim=" + String(bright);
  35. myNextion.sendCommand(dim.c_str());
  36.  
  37. sensors_event_t event;
  38. dht.temperature().getEvent(&event);
  39. myNextion.setComponentText("temp", String(event.temperature));
  40. //delay(100);
  41. dht.humidity().getEvent(&event);
  42. myNextion.setComponentText("fukt", String(event.relative_humidity));
  43.  
  44. tmElements_t tm;
  45. (RTC.read(tm));
  46.  
  47. if (tm.Hour == 1) {myNextion.setComponentText("tim","01");}
  48. if (tm.Hour == 2) {myNextion.setComponentText("tim","02");}
  49. if (tm.Hour == 3) {myNextion.setComponentText("tim","03");}
  50. if (tm.Hour == 4) {myNextion.setComponentText("tim","04");}
  51. if (tm.Hour == 5) {myNextion.setComponentText("tim","05");}
  52. if (tm.Hour == 6) {myNextion.setComponentText("tim","06");}
  53. if (tm.Hour == 7) {myNextion.setComponentText("tim","07");}
  54. if (tm.Hour == 8) {myNextion.setComponentText("tim","08");}
  55. if (tm.Hour == 9) {myNextion.setComponentText("tim","09");}
  56. if (tm.Hour > 9) {myNextion.setComponentText("tim", String(tm.Hour));}
  57.  
  58. if (tm.Minute == 1) {myNextion.setComponentText("min","01");}
  59. if (tm.Minute == 2) {myNextion.setComponentText("min","02");}
  60. if (tm.Minute == 3) {myNextion.setComponentText("min","03");}
  61. if (tm.Minute == 4) {myNextion.setComponentText("min","04");}
  62. if (tm.Minute == 5) {myNextion.setComponentText("min","05");}
  63. if (tm.Minute == 6) {myNextion.setComponentText("min","06");}
  64. if (tm.Minute == 7) {myNextion.setComponentText("min","07");}
  65. if (tm.Minute == 8) {myNextion.setComponentText("min","08");}
  66. if (tm.Minute == 9) {myNextion.setComponentText("min","09");}
  67. if (tm.Minute > 9) {myNextion.setComponentText("min", String(tm.Minute));}
  68.  
  69. if (tm.Month == 1) {myNextion.setComponentText("man","01");}
  70. if (tm.Month == 2) {myNextion.setComponentText("man","02");}
  71. if (tm.Month == 3) {myNextion.setComponentText("man","03");}
  72. if (tm.Month == 4) {myNextion.setComponentText("man","04");}
  73. if (tm.Month == 5) {myNextion.setComponentText("man","05");}
  74. if (tm.Month == 6) {myNextion.setComponentText("man","06");}
  75. if (tm.Month == 7) {myNextion.setComponentText("man","07");}
  76. if (tm.Month == 8) {myNextion.setComponentText("man","08");}
  77. if (tm.Month == 9) {myNextion.setComponentText("man","09");}
  78. if (tm.Month > 9) {myNextion.setComponentText("man", String(tm.Month));}
  79.  
  80. if (tm.Day == 1) {myNextion.setComponentText("dag","01");}
  81. if (tm.Day == 2) {myNextion.setComponentText("dag","02");}
  82. if (tm.Day == 3) {myNextion.setComponentText("dag","03");}
  83. if (tm.Day == 4) {myNextion.setComponentText("dag","04");}
  84. if (tm.Day == 5) {myNextion.setComponentText("dag","05");}
  85. if (tm.Day == 6) {myNextion.setComponentText("dag","06");}
  86. if (tm.Day == 7) {myNextion.setComponentText("dag","07");}
  87. if (tm.Day == 8) {myNextion.setComponentText("dag","08");}
  88. if (tm.Day == 9) {myNextion.setComponentText("dag","09");}
  89. if (tm.Day > 9) {myNextion.setComponentText("dag", String(tm.Day));}
  90. myNextion.setComponentText("ar", String(tmYearToCalendar(tm.Year)));
  91. delay(1000);
  92.  
  93. void b1PushCallback(void *ptr); // Press event for button b1
  94. {
  95. digitalWrite(13, HIGH); }
  96. void b1PopCallback(void *ptr); // Release event for button b1
  97. { digitalWrite(13, LOW); // Turn OFF internal LED
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement