Touch sensor use version works

This commit is contained in:
Joe Tretter
2022-09-20 13:09:20 -05:00
parent 89f5541124
commit 0e30ac9d5a

View File

@@ -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 <b>" +
String(bubbleFreqSec) + "</b> Seconds. [" + String(millis()) + "/" +
String(lastMillis) + "/" + String(isBubbleFirstContact) + "/" +
String(digitalRead(BUBBLE_GPIO)) +
String(bVal) +
"]"
"<script>window.setTimeout(_=>{window.location.reload();}"
",1000)</script>");
@@ -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);
}