diff --git a/include/htu21d.h b/include/htu21d.h new file mode 100644 index 0000000..14c4522 --- /dev/null +++ b/include/htu21d.h @@ -0,0 +1,41 @@ +#include +#include +//#include +#include + +Adafruit_HTU21DF htu = Adafruit_HTU21DF(); + +bool F_HTU_21D; +float K_HTU= -0.00; + +struct { + char temperature[15] = {0}; + char humity[15] = {0}; +} htuData; + +void init_HTU21(){ + F_HTU_21D = false; + if (!htu.begin()) { + Serial.println("Couldn't find sensor HUT21D!"); + + }else{ + F_HTU_21D = true; + Serial.println("HUT21D gefunden"); + } + +} + +void read_HTU21D() { + float t = htu.readTemperature(); + t = t + KorrekturTemperatur; + dtostrf(t,7,1,htuData.temperature); + float h = htu.readHumidity(); + dtostrf(h,7,1,htuData.humity); + Serial.print("Temperature (HTU21D):\t"); + Serial.print(htuData.temperature); + Serial.println(" °C"); + Serial.print("Luftfeuchtigkeit:\t"); + Serial.print(htuData.humity); + Serial.println(" %"); + +} diff --git a/platformio.ini b/platformio.ini index 8d97eb8..e1aa506 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,3 +19,9 @@ lib_deps = # The exact version bodmer/TFT_eSPI @ 2.5.43 paulstoffregen/XPT2046_Touchscreen @ 0.0.0-alpha+sha.26b691b2c8 + adafruit/Adafruit Unified Sensor @ 1.1.14 + #adafruit/Adafruit HTU21DF Library @ 1.0.5 + +build_flags = ${env.build_flags} + -DKorrekturTemperatur=0.0 + diff --git a/src/main.cpp b/src/main.cpp index 92f866c..365a884 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,8 @@ Updated by Bodmer for variable meter size */ +#define ledGreen 16 + // Define meter size as 1 for tft.rotation(0) or 1.3333 for tft.rotation(1) #define M_SIZE 1.3333 @@ -25,6 +27,7 @@ TFT_eSPI tft = TFT_eSPI(); // Invoke custom library #define TFT_GREY 0x5AEB + float ltx = 0; // Saved x coord of bottom of needle uint16_t osx = M_SIZE*120, osy = M_SIZE*120; // Saved x & y coords uint32_t updateTime = 0; // time for next update @@ -41,14 +44,19 @@ void plotNeedle(int value, byte ms_delay); void setup(void) { tft.init(); tft.setRotation(1); - Serial.begin(57600); // For debug + Serial.begin(115200); // For debug tft.fillScreen(TFT_BLACK); tft.drawString("Raumfeuchtigkeit", 1, 210, 4); + //I2C_2.begin(SDA_2, SCL_2, I2C_FREQ); //delay(9000); analogMeter(); // Draw analogue meter updateTime = millis(); // Next update time + pinMode(ledGreen, OUTPUT); + analogWrite(ledGreen, 102); + //init_HTU21(); + delay(5000); } @@ -99,23 +107,29 @@ void analogMeter() int y3 = sy2 * M_SIZE*100 + M_SIZE*140; // Yellow zone limits - //if (i >= -50 && i < 0) { - // tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW); - // tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW); - //} + if (i >= -50 && i < 0) { + tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW); + tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW); + } // Green zone limits - if (i >= 0 && i < 25) { + if (i >= 0 && i < 15) { tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_GREEN); tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_GREEN); } // Orange zone limits - if (i >= 25 && i < 50) { + if (i >= 15 && i < 25) { tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_ORANGE); tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_ORANGE); } + // Red zone limits + if (i >= 25 && i < 50) { + tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_RED); + tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_RED); + } + // Short scale tick length if (i % 25 != 0) tl = 8;