This commit is contained in:
BOT Alex 2024-05-13 13:05:45 +02:00
parent b15a18fc12
commit 462690a82d
1 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,125 @@
#include <M5StickCPlus2.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
WiFiMulti wifiMulti;
HTTPClient http;
#define buttonPin 26
#define led1 25
#define led2 0
#define longPressThreshhold 150
bool lightA, lightB = false;
void initRandomSeed()
{
wifiMulti.addAP("AIRPORT-FREE-WIFI-NEW", "alexalex");
wifiMulti.addAP("Next-Guest", "");
long startStartedWifi = millis();
while ((wifiMulti.run() != WL_CONNECTED))
{
Serial.println("Connecting to wifi...");
}
randomSeed(millis() - startStartedWifi);
}
void reset(){
//assert(false);
lightA = random(2) == 1 ? true : false;
lightB = random(2) == 1 ? true : false;
}
void drawUI(){
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextSize(4);
M5.Lcd.println("Light A: " + String(lightA));
M5.Lcd.println("Light B: " + String(lightB));
M5.Lcd.setTextSize(2);
M5.Lcd.println("Answer is long press?: " + String(lightA ^ lightB));
}
void enterWinLoop(){
while (true){
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
if (digitalRead(buttonPin) == HIGH){
}
}
}
void setup()
{
M5.Lcd.begin();
M5.Lcd.setRotation(1);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextSize(4);
M5.Lcd.println("Loading..");
pinMode(39, INPUT_PULLDOWN);
pinMode(buttonPin, INPUT_PULLDOWN);
pinMode(led1, OUTPUT_OPEN_DRAIN);
pinMode(led2, OUTPUT_OPEN_DRAIN);
Serial.begin(115200);
initRandomSeed();
reset();
M5.Lcd.fillScreen(BLACK);
}
long pressedTime = 0;
long releasedTime = 0;
bool pressed = false;
void loop()
{
drawUI();
if (digitalRead(39) == LOW){
reset();
}
if (lightA)
digitalWrite(led1, LOW);
else
digitalWrite(led1, HIGH);
if (lightB)
digitalWrite(led2, LOW);
else
digitalWrite(led2, HIGH);
if (!pressed && digitalRead(buttonPin) == HIGH)
{
// On click
pressedTime = millis();
pressed = true;
}
else if (pressed && digitalRead(buttonPin) == LOW)
{
// On release
releasedTime = millis();
pressed = false;
long totalPressedTime = releasedTime - pressedTime;
Serial.println("Total time: " + String(totalPressedTime));
if (totalPressedTime < longPressThreshhold){
Serial.println("Short press detected!");
}else{
Serial.println("Long press detected!");
}
}
}