From 5e214b68520f628ce3f662200cd4b143f47e5afc Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Tue, 14 May 2024 13:45:34 +0200 Subject: [PATCH] Wires module done --- ModuleWires/ModuleWires.ino | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/ModuleWires/ModuleWires.ino b/ModuleWires/ModuleWires.ino index e69de29..7e93a4f 100644 --- a/ModuleWires/ModuleWires.ino +++ b/ModuleWires/ModuleWires.ino @@ -0,0 +1,65 @@ +#include + +#define correctWirePin 26 +#define wrongWirePin 25 +#define extenderPin 0 + +bool hasWon, hasLost = false; + +void reset() +{ + hasWon = false; + hasLost = false; +} + +void setup() +{ + M5.begin(); + M5.Lcd.begin(); + M5.Lcd.setRotation(3); + + pinMode(correctWirePin, INPUT_PULLDOWN); + pinMode(wrongWirePin, INPUT_PULLDOWN); + + pinMode(extenderPin, OUTPUT_OPEN_DRAIN); + + Serial.begin(9600); +} + +void loop() +{ + if (hasWon){ + digitalWrite(extenderPin, LOW); + }else + digitalWrite(extenderPin, HIGH); + + if (digitalRead(correctWirePin) == HIGH && digitalRead(wrongWirePin) == HIGH) + { + reset(); + } + + Serial.println("Won: " + String(hasWon)); + Serial.println("Lost: " + String(hasLost)); + + if (hasWon || hasLost) return; + else{ + M5.Lcd.fillScreen(BLACK); + M5.Lcd.setCursor(0, 0); + M5.Lcd.setTextSize(2); + M5.Lcd.setTextColor(WHITE); + M5.Lcd.println("Waiting for cut..."); + } + + if (digitalRead(correctWirePin) == LOW) + { + M5.Lcd.fillScreen(GREEN); + hasWon = true; + } + + if (digitalRead(wrongWirePin) == LOW) + { + M5.Lcd.fillScreen(RED); + hasLost = true; + } + delay(50); +} \ No newline at end of file