diff --git a/src/main.cpp b/src/main.cpp
index 006e501..dc4bb40 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,8 +9,9 @@ const char* ssid = "JoNelsDarlings";
const char* password = "Paris2016";
const int BUBBLE_GPIO = 4;
boolean isBubbleFirstContact = true;
-unsigned long bubbleFreqSec = 0;
+double bubbleFreqSec = 0;
unsigned long lastMillis = millis();
+unsigned int bVal;
AsyncWebServer server(80);
@@ -65,7 +66,7 @@ void setup(void) {
"Hi! This is the Wine-Sensor. Last bubble frequency: every " +
String(bubbleFreqSec) + " Seconds. [" + String(millis()) + "/" +
String(lastMillis) + "/" + String(isBubbleFirstContact) + "/" +
- String(digitalRead(BUBBLE_GPIO)) +
+ String(bVal) +
"]"
"");
@@ -74,25 +75,30 @@ void setup(void) {
AsyncElegantOTA.begin(&server); // Start AsyncElegantOTA
server.begin();
Serial.println("HTTP server started");
-
- pinMode(BUBBLE_GPIO, INPUT_PULLUP);
}
void loop(void) {
- digitalWrite(LED_BUILTIN, digitalRead(BUBBLE_GPIO));
+ bVal = touchRead(BUBBLE_GPIO);
+ if (bVal == 0) {
+ digitalWrite(BUILTIN_LED, HIGH);
+ } else {
+ digitalWrite(BUILTIN_LED, LOW);
+ }
+ // writeToOled("* " + String(bVal));
// This runs real fast, so make sure that only the "first contact" is measured
- if ((digitalRead(BUBBLE_GPIO) == LOW) && isBubbleFirstContact) {
+ if ((bVal == 0) && (isBubbleFirstContact)) {
if (millis() > lastMillis) { // don't measure if we had an overflow...
- bubbleFreqSec = (millis() - lastMillis) / 1000;
- writeToOled("Freq: " + String(bubbleFreqSec));
+ bubbleFreqSec = (double)(millis() - lastMillis) / 1000;
}
lastMillis = millis();
isBubbleFirstContact = false;
- } else if ((digitalRead(BUBBLE_GPIO) == HIGH)) {
+ } else if (0 != bVal) {
isBubbleFirstContact = true;
}
+ writeToOled("F:" + String(bubbleFreqSec, 2) + "\n[" + String(bVal) + "]");
+
// need to slow it down a bit to prevent fluctuating state cahange
- delay(100);
+ delay(10);
}