Touch sensor use version works
This commit is contained in:
26
src/main.cpp
26
src/main.cpp
@@ -9,8 +9,9 @@ const char* ssid = "JoNelsDarlings";
|
|||||||
const char* password = "Paris2016";
|
const char* password = "Paris2016";
|
||||||
const int BUBBLE_GPIO = 4;
|
const int BUBBLE_GPIO = 4;
|
||||||
boolean isBubbleFirstContact = true;
|
boolean isBubbleFirstContact = true;
|
||||||
unsigned long bubbleFreqSec = 0;
|
double bubbleFreqSec = 0;
|
||||||
unsigned long lastMillis = millis();
|
unsigned long lastMillis = millis();
|
||||||
|
unsigned int bVal;
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ void setup(void) {
|
|||||||
"Hi! This is the Wine-Sensor. Last bubble frequency: every <b>" +
|
"Hi! This is the Wine-Sensor. Last bubble frequency: every <b>" +
|
||||||
String(bubbleFreqSec) + "</b> Seconds. [" + String(millis()) + "/" +
|
String(bubbleFreqSec) + "</b> Seconds. [" + String(millis()) + "/" +
|
||||||
String(lastMillis) + "/" + String(isBubbleFirstContact) + "/" +
|
String(lastMillis) + "/" + String(isBubbleFirstContact) + "/" +
|
||||||
String(digitalRead(BUBBLE_GPIO)) +
|
String(bVal) +
|
||||||
"]"
|
"]"
|
||||||
"<script>window.setTimeout(_=>{window.location.reload();}"
|
"<script>window.setTimeout(_=>{window.location.reload();}"
|
||||||
",1000)</script>");
|
",1000)</script>");
|
||||||
@@ -74,25 +75,30 @@ void setup(void) {
|
|||||||
AsyncElegantOTA.begin(&server); // Start AsyncElegantOTA
|
AsyncElegantOTA.begin(&server); // Start AsyncElegantOTA
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.println("HTTP server started");
|
Serial.println("HTTP server started");
|
||||||
|
|
||||||
pinMode(BUBBLE_GPIO, INPUT_PULLUP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void) {
|
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
|
// 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...
|
if (millis() > lastMillis) { // don't measure if we had an overflow...
|
||||||
bubbleFreqSec = (millis() - lastMillis) / 1000;
|
bubbleFreqSec = (double)(millis() - lastMillis) / 1000;
|
||||||
writeToOled("Freq: " + String(bubbleFreqSec));
|
|
||||||
}
|
}
|
||||||
lastMillis = millis();
|
lastMillis = millis();
|
||||||
isBubbleFirstContact = false;
|
isBubbleFirstContact = false;
|
||||||
} else if ((digitalRead(BUBBLE_GPIO) == HIGH)) {
|
} else if (0 != bVal) {
|
||||||
isBubbleFirstContact = true;
|
isBubbleFirstContact = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeToOled("F:" + String(bubbleFreqSec, 2) + "\n[" + String(bVal) + "]");
|
||||||
|
|
||||||
// need to slow it down a bit to prevent fluctuating state cahange
|
// need to slow it down a bit to prevent fluctuating state cahange
|
||||||
delay(100);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user