Advertisement
Barkenator

Untitled

Aug 28th, 2016
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "U8glib.h"
  2. #include "DHT.h"
  3.  
  4. #define DHTPIN 5
  5. #define DHTTYPE DHT22
  6.  
  7. DHT dht(DHTPIN, DHTTYPE);
  8.  
  9. U8GLIB_SH1106_128X64 u8g  (12, 11, 8, 9, 10); // (D0, D1, CS, DC, RST)
  10. U8GLIB_SH1106_128X64 u8g2 (12, 11, 7, 9, 10); // (D0, D1, CS, DC, RST)
  11.  
  12. void setup() {
  13.   dht.begin();
  14. }
  15.  
  16. void drawLocal() {
  17.   int tempLocal = dht.readTemperature();
  18.   int humiLocal = dht.readHumidity();
  19.  
  20.   u8g.setFont       (u8g_font_unifont);
  21.   u8g.drawFrame     (1, 1, 126, 62);
  22.  
  23.   u8g.drawStr       (10, 20, "LOCAL");
  24.  
  25.   u8g.drawStr       (10, 40, "TEMP:");
  26.   u8g.setPrintPos   (90, 40);
  27.   u8g.print(tempLocal);
  28.   u8g.drawStr       (109, 40, "C");
  29.  
  30.   u8g.drawStr       (10, 53, "HUMI:");
  31.   u8g.setPrintPos   (90, 53);
  32.   u8g.print(humiLocal);
  33.   u8g.drawStr       (109, 53, "%");
  34. }
  35.  
  36. void drawAPI() {
  37.   int tempAPI = 99;
  38.   int humiAPI = 66;
  39.  
  40.   u8g2.setFont      (u8g_font_unifont);
  41.   u8g2.drawFrame    (1, 1, 126, 62);
  42.  
  43.   u8g2.drawStr      (10, 20, "FORECAST.io");
  44.  
  45.   u8g2.drawStr       (10, 40, "TEMP:");
  46.   u8g2.setPrintPos   (90, 40);
  47.   u8g2.print(tempAPI);
  48.   u8g2.drawStr       (109, 40, "C");
  49.  
  50.   u8g2.drawStr       (10, 53, "HUMI:");
  51.   u8g2.setPrintPos   (90, 53);
  52.   u8g2.print(humiAPI);
  53.   u8g2.drawStr       (109, 53, "%");
  54. }
  55.  
  56. void loop() {
  57.  
  58.   u8g.firstPage();
  59.   do {
  60.     drawLocal();
  61.   } while (u8g.nextPage() );
  62.  
  63.   u8g2.firstPage();
  64.   do {
  65.     drawAPI();
  66.   } while (u8g2.nextPage() );
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement