Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: mod9_DHT22_SSD1306.ino
- * Date: 2021/10/14
- * Author: fsc
- * Version 1.0
- */
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #include <DHT.h>
- #define OLED_RESET 4
- #define SSD1306_LCDWIDTH 128 // OLED mit 128 Picel in der Breite
- #define SSD1306_LCDHEIGHT 64 // OLED mit 64 Pixel in der Höhe
- Adafruit_SSD1306 display(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT, &Wire, OLED_RESET);
- #define DHTPIN 8 // DHT22 an Pin 8
- #define DHTTYPE DHT22 // DHT22 auswählen
- DHT dht(DHTPIN, DHTTYPE); // Objekt mit Parameter anlegen
- char temperature[] = "00.0 C";
- char humidity[] = "00.0 %";
- void setup(void) {
- display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // OLED auf I2C-Adresse 0x3D festlegen
- dht.begin(); // DHT initialisieren
- delay(1000);
- // Anzeigepuffer löschen
- display.clearDisplay();
- display.drawFastHLine(0, 32, SSD1306_LCDWIDTH, WHITE);
- display.setTextSize(1);
- display.setTextColor(WHITE, BLACK);
- display.setCursor(10, 5); // Position der Pixel (x,y)
- display.print("DHT22 TEMPERATUR:");
- display.setCursor(10, 37);
- display.print("DHT22 LUFTFEUCHTE:");
- display.display();
- }
- void loop() {
- // Wert für Luftfeuchte auslesen
- byte RH = dht.readHumidity();
- // Wert für Temperatur auslesen
- byte Temp = dht.readTemperature();
- temperature[0] = Temp / 10 + 48;
- temperature[1] = Temp % 10 + 48;
- humidity[0] = RH / 10 + 48;
- humidity[1] = RH % 10 + 48;
- display.setCursor(46, 20);
- display.print(temperature);
- display.setCursor(46, 52);
- display.print(humidity);
- display.drawRect(71, 20, 3, 3, WHITE); // Grad-Symbol zeichnen ( ° ), nicht im Zeichensatz enthalten
- display.display();
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement