diff options
author | Tanishka Suwalka <tanishkas@ruc.dk> | 2025-04-17 20:15:09 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-17 20:15:09 +0200 |
commit | 61ad3b1960d9b20106fa9a8baeba8c16ec4848f1 (patch) | |
tree | 16d0bd2f4c4e2319ba1fde8e9f137d7bda989fb0 /vote | |
parent | 410a67b51d58ef3373ddfd9cfa08589a462cb046 (diff) |
track vote outcome
Diffstat (limited to 'vote')
-rw-r--r-- | vote/vote.ino | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vote/vote.ino b/vote/vote.ino index e658f0b..29618f1 100644 --- a/vote/vote.ino +++ b/vote/vote.ino @@ -39,6 +39,13 @@ // Validity timing thresholds const unsigned long VOTE_TIME_TOLERANCE = 1 * 60 * 1000; // 1 minute +// LED pin setup +int LED1 = 2; // Blue +int LED2 = 33; // Green + +//Global variable to track vote outcome +bool waterIsDrinkable = true; // true means LED off, false means LED on + // Classify gape state enum MusselGapState { Closed, @@ -224,6 +231,7 @@ void concludeVote() { // Determine the threshold (half of total valid votes, rounded down) int threshold = totalValidVotes / 2; + waterIsDrinkable = (openVotes >= threshold); // Same or more "Open" votes than the threshold means water is ok if (openVotes >= threshold) { @@ -267,6 +275,14 @@ void setup() { Serial.begin(115200); esp_log_level_set("*", ESP_LOG_DEBUG); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); // Start with LED off (HIGH = off on active-low boards) + + pinMode(LED1, OUTPUT); + pinMode(LED2, OUTPUT); + digitalWrite(LED1, LOW); + digitalWrite(LED2, LOW); + // setup Bluetooth BLEDevice::init(""); pBLEScan = BLEDevice::getScan(); @@ -286,5 +302,18 @@ void loop() { concludeVote(); cleanOldBallotData(); // Tidy the voter stack + digitalWrite(LED_BUILTIN, waterIsDrinkable ? LOW : HIGH); + + // LED Logic: GREEN if drinkable, RED if not + if (waterIsDrinkable) { + digitalWrite(LED2, HIGH); // GREEN ON + digitalWrite(LED1, LOW); // RED OFF + Serial.println("Water is DRINKABLE - GREEN LED ON"); + } else { + digitalWrite(LED2, LOW); // GREEN OFF + digitalWrite(LED1, HIGH); // RED ON + Serial.println("Water is NOT DRINKABLE - RED LED ON"); + } + delay(500); } |