Created
January 16, 2016 22:21
-
-
Save rmetzler/8baa17a2f468ac988864 to your computer and use it in GitHub Desktop.
Arduino, DHT11 and OLED display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <SPI.h> | |
| #include <Wire.h> | |
| #include <DHT.h> | |
| #include <Adafruit_GFX.h> | |
| #include <Adafruit_SSD1306.h> | |
| #define OLED_RESET 4 // not used / nicht genutzt bei diesem Display | |
| Adafruit_SSD1306 display(OLED_RESET); | |
| #define DHTPIN 2 // what digital pin we're connected to | |
| #define DHTTYPE DHT11 // DHT 11 | |
| DHT dht(DHTPIN, DHTTYPE); | |
| void setup() { | |
| // initialize with the I2C addr 0x3C / mit I2C-Adresse 0x3c initialisieren | |
| display.begin(SSD1306_SWITCHCAPVCC, 0x3C); | |
| dht.begin(); | |
| } | |
| void loop() { | |
| float t = dht.readTemperature(); | |
| float h = dht.readHumidity(); | |
| display.clearDisplay(); | |
| // set text color / Textfarbe setzen | |
| display.setTextColor(WHITE); | |
| // set text size / Textgroesse setzen | |
| display.setTextSize(1); | |
| // set text cursor position / Textstartposition einstellen | |
| display.setCursor(1, 0); | |
| // show text / Text anzeigen | |
| display.println("temperature"); | |
| display.setTextSize(2); | |
| display.println(" " + String(t, 0) + "C"); | |
| display.setTextSize(1); | |
| display.println("humidity"); | |
| display.setTextSize(2); | |
| display.println(" " + String(h, 0) + "%"); | |
| display.display(); | |
| delay(2000); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment