
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71  | 
						#include <Wire.h> #include "SSD1306.h" #include "DHT.h" #define DHTPIN D3 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); SSD1306 display(0x3c, 4, 5); int intTemperature = 0; int intHumidity = 0; int firstRun = 1; String lastValidTemp = ""; String lastValidHum = ""; void setup() {   display.init();   display.flipScreenVertically(); } void loop() {   getDHT(); // reads DHT11 Sensor Data   display.clear();   drawDHT(); // show DHT sensor data on OLED     display.display(); // Display all in OLED   firstRun = 0; } void getDHT() {   intTemperature = dht.readTemperature();   intHumidity = dht.readHumidity(); } void drawDHT() {   int x = 0;   int y = 0;   display.setFont(ArialMT_Plain_16);   display.setTextAlignment(TEXT_ALIGN_LEFT);   display.drawString(30 + x, y, "freeelec.ir");   display.setFont(ArialMT_Plain_10);   display.setTextAlignment(TEXT_ALIGN_LEFT);   display.drawString(43 + x, 20 + y, "DHT11");   display.setFont(ArialMT_Plain_10);   display.setTextAlignment(TEXT_ALIGN_LEFT);   display.drawString(0 + x, 25 + y, "Hum");   display.setFont(ArialMT_Plain_24);   String humdht22 = String(intHumidity);   if (humdht22.length() <= 2) {     display.drawString(0 + x, 35 + y, humdht22 + "%");     lastValidHum = humdht22;   } else {     display.drawString(0 + x, 35 + y, lastValidHum + "%");   }   display.setFont(ArialMT_Plain_10);   display.setTextAlignment(TEXT_ALIGN_LEFT);   display.drawString(95 + x, 25 + y, "Temp");   display.setFont(ArialMT_Plain_24);   String tempdht22 = String(intTemperature);   if (tempdht22.length() <= 2) {     display.drawString(70 + x, 35 + y, tempdht22 + "^C");     lastValidTemp = tempdht22;   } else {     display.drawString(70 + x, 35 + y, lastValidTemp + "^C");   } }  |