Wires module done

This commit is contained in:
BOT Alex 2024-05-14 13:45:34 +02:00
parent e910c2451e
commit 5e214b6852
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
#include <M5StickCPlus2.h>
#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);
}