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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #include “U8g2lib.h” #include “Adafruit_AHTX0.h” // Namen des Sensors (aht) festlegen Adafruit_AHTX0 aht; // 1,3 Zoll SH1106 // U8G2_SH1106_128X64_NONAME_1_HW_I2C oled(U8G2_R0, U8X8_PIN_NONE); // 0,96 Zoll SSD1306 U8G2_SSD1306_128X64_NONAME_1_HW_I2C oled(U8G2_R0, U8X8_PIN_NONE); // Bild Thermometer: Breite und Höhe definieren #define ThermometerBreite 21 #define ThermometerHoehe 64 // Array Bild Thermometer static unsigned char Thermometer[] = { 0xf0, 0x7f, 0x00, 0xf0, 0x7f, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0xff, 0xff, 0x0f, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0xff, 0xff, 0x0f, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0xff, 0xff, 0x0f, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0x30, 0x60, 0x00, 0xf0, 0x7f, 0x00, 0xf0, 0x7f, 0x00, 0xf0, 0xff, 0x01, 0xf8, 0xe0, 0x03, 0xfc, 0xff, 0x07, 0xfe, 0xff, 0x0f, 0x0e, 0x00, 0x0e, 0x07, 0x00, 0x1c, 0xff, 0xff, 0x1f, 0xff, 0xff, 0x1f, 0x03, 0x00, 0x18, 0x03, 0x00, 0x18, 0xff, 0xff, 0x1f, 0xff, 0xff, 0x1f, 0x07, 0x00, 0x1c, 0x0e, 0x00, 0x0e, 0xfe, 0xff, 0x0f, 0xfc, 0xff, 0x07, 0xf8, 0xe0, 0x03, 0xf0, 0xff, 0x01, 0xc0, 0x7f, 0x00 }; void setup() { // Display starten oled.begin(); // AHT starten aht.begin(); // Kontrast maximal 255 oled.setContrast(200); // Farbe weiß setzen oled.setDrawColor(1); // Schriftart festlegen oled.setFont(u8g2_font_helvB14_tf); } void loop() { // Variablen für Temperatur und Luftfeuchtigkeit definieren sensors_event_t Feuchtigkeit, Temperatur; // Werte Temperatur und Luftfeuchtigkeit erfassen aht.getEvent(&Feuchtigkeit, &Temperatur); oled.firstPage(); do { // Thermometer anzeigen oled.drawXBM(10, 1, ThermometerBreite, ThermometerHoehe, Thermometer); // . durch , ersetzen String AnzeigeTemperatur = PunktErsetzen(String(Temperatur.temperature)); String AnzeigeLuftfeuchtigkeit = PunktErsetzen(String(Feuchtigkeit.relative_humidity)); // Werte auf dem OLED anzeigen oled.setCursor(40, 20); oled.print(AnzeigeTemperatur + ” ” +char(176) + “C”); oled.setCursor(40, 50); oled.print(AnzeigeLuftfeuchtigkeit + ” %”); } while (oled.nextPage()); delay(2000); } // Funktion . durch , ersetzen String PunktErsetzen(String ErsatzString) { ErsatzString.replace(“.”, “,”); return ErsatzString; } |
Letzte Aktualisierung: