diff --git a/src/config.cpp b/src/config.cpp index 8c6e814..669456e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -19,6 +19,12 @@ const uint16_t SCALE_LEVEL_WEIGHT = 500; uint16_t defaultScaleCalibrationValue = 430; // ***** HX711 +// ***** TTP223 (Touch Sensor) +// TTP223 circuit wiring +const uint8_t TTP223_PIN = 15; +// ***** TTP223 + + // ***** Display // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) // On an ESP32: 21(SDA), 22(SCL) diff --git a/src/config.h b/src/config.h index 822ff8d..dd6cb20 100644 --- a/src/config.h +++ b/src/config.h @@ -11,6 +11,8 @@ extern const uint8_t LOADCELL_SCK_PIN; extern const uint8_t calVal_eepromAdress; extern const uint16_t SCALE_LEVEL_WEIGHT; +extern const uint8_t TTP223_PIN; + extern const int8_t OLED_RESET; extern const uint8_t SCREEN_ADDRESS; extern const uint8_t SCREEN_WIDTH; diff --git a/src/main.cpp b/src/main.cpp index 0b2c635..69b00aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,6 @@ void setup() { setupWebserver(server); // Spoolman API - // api.cpp initSpoolman(); // Bambu MQTT @@ -48,6 +47,7 @@ void setup() { // NFC Reader startNfc(); + // Scale start_scale(); // WDT initialisieren mit 10 Sekunden Timeout @@ -56,6 +56,9 @@ void setup() { // Aktuellen Task (loopTask) zum Watchdog hinzufügen esp_task_wdt_add(NULL); + + // Touch Sensor + pinMode(TTP223_PIN, INPUT_PULLUP); } @@ -91,6 +94,12 @@ const unsigned long wifiCheckInterval = 60000; // Überprüfe alle 60 Sekunden ( void loop() { unsigned long currentMillis = millis(); + // Überprüfe den Status des Touch Sensors + if (digitalRead(TTP223_PIN) == LOW) + { + tareScale(); + } + // Überprüfe regelmäßig die WLAN-Verbindung if (intervalElapsed(currentMillis, lastWifiCheckTime, wifiCheckInterval)) { @@ -158,25 +167,6 @@ void loop() { { lastWeightReadTime = currentMillis; - // Prüfen ob die Waage korrekt genullt ist - if ((weight > 0 && weight < 5) || weight < -1) - { - if(scaleTareCounter < 5) - { - scaleTareCounter++; - } - else - { - scaleTareRequest = true; - scaleTareCounter = 0; - } - - } - else - { - scaleTareCounter = 0; - } - // Prüfen ob das Gewicht gleich bleibt und dann senden if (weight == lastWeight && weight > 5) {