Advertisement
Guest User

nextion

a guest
Apr 19th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. /*
  2.  
  3. Ricardo Mena C
  4. ricardo@crcibernetica.com
  5. http://crcibernetica.com
  6.  
  7. This example code is in public domain
  8.  
  9. */
  10.  
  11. #include <SoftwareSerial.h>
  12. #include <Nextion.h>
  13. #include <TimeLib.h>
  14. #include <DS1307RTC.h>
  15. #include <Wire.h>
  16. #include <DHT.h>
  17. #include <DHT_U.h>
  18. #define DHTPIN 6
  19. #define DHTTYPE DHT22
  20. DHT_Unified dht(DHTPIN, DHTTYPE);
  21. uint32_t delayMS;
  22.  
  23. SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino
  24.  
  25. Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps
  26.  
  27. void setup() {
  28. Serial.begin(9600);
  29. dht.begin();
  30. myNextion.init();
  31.  
  32. }
  33.  
  34.  
  35. void loop() {
  36. sensors_event_t event;
  37. int brightness = (event.relative_humidity);
  38. int bright = map(brightness, 30.0, 100.0, 100, 10);
  39. String dim = "dim=" + String(bright);
  40. myNextion.sendCommand(dim.c_str());
  41.  
  42.  
  43. dht.temperature().getEvent(&event);
  44. myNextion.setComponentText("temp", String(event.temperature));
  45. //delay(100);
  46. dht.humidity().getEvent(&event);
  47. myNextion.setComponentText("fukt", String(event.relative_humidity));
  48.  
  49.  
  50.  
  51.  
  52. tmElements_t tm;
  53. (RTC.read(tm));
  54.  
  55.  
  56. myNextion.setComponentText("tim", String(tm.Hour));
  57. myNextion.setComponentText("min", String(tm.Minute));
  58. myNextion.setComponentText("ar", String(tmYearToCalendar(tm.Year)));
  59. myNextion.setComponentText("man", String(tm.Month));
  60. myNextion.setComponentText("dag", String(tm.Day));
  61.  
  62. delay(1000);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement