From 55f94cd2d077bf58b51f19caa436a0af15b80fef Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Wed, 15 May 2024 13:41:20 +0200 Subject: [PATCH] Sync --- ModuleMath/MathSystem.h | 2 +- ModuleMath/ModuleMath.ino | 2 +- ModuleTimer/ModuleTimer.ino | 74 +++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 ModuleTimer/ModuleTimer.ino diff --git a/ModuleMath/MathSystem.h b/ModuleMath/MathSystem.h index d855671..554b80b 100644 --- a/ModuleMath/MathSystem.h +++ b/ModuleMath/MathSystem.h @@ -12,7 +12,7 @@ enum class Operator{ }; void initRandomSeed(){ - M5.IMU.Init(); + M5.Imu.Init(); float accX, accY, accZ; delay(250); // Wait for imu init M5.IMU.getAccelData(&accX, &accY, &accZ); diff --git a/ModuleMath/ModuleMath.ino b/ModuleMath/ModuleMath.ino index b19e52f..b2936a2 100644 --- a/ModuleMath/ModuleMath.ino +++ b/ModuleMath/ModuleMath.ino @@ -1,4 +1,4 @@ -#include +#include #include "InputSystem.h" #include "MathSystem.h" diff --git a/ModuleTimer/ModuleTimer.ino b/ModuleTimer/ModuleTimer.ino new file mode 100644 index 0000000..3bfdb99 --- /dev/null +++ b/ModuleTimer/ModuleTimer.ino @@ -0,0 +1,74 @@ +#include + +#define penaltyAmount 30 * 1000 +#define drawInterval 1000 + +unsigned long startTime; +const unsigned long countdownDuration = 5 * 60 * 1000; // 5 minutes in milliseconds +unsigned long penalties = 0; + +void reset() +{ + startTime = millis(); + penalties = 0; +} + +void setup() +{ + M5.begin(); + M5.Lcd.begin(); + M5.Lcd.fillScreen(TFT_BLACK); // Set initial background color + startTime = millis(); // Record the start time + + Serial.begin(9600); +} + +bool pressed = false; +void loop() +{ + unsigned long elapsedTime = millis() - startTime + penalties; + unsigned long remainingTime = countdownDuration - elapsedTime; + + // Check if the time has run out + if (remainingTime <= 0) + { + displayTime(0, 0); // Display 00:00 + turnScreenRed(); + return; + } + + // Calculate remaining minutes and seconds + unsigned long minutes = remainingTime / (60 * 1000); + unsigned long seconds = (remainingTime / 1000) % 60; + + // Display remaining time + if (millis() % drawInterval < 10) + { + M5.Lcd.fillScreen(BLACK); + displayTime(minutes, seconds); + } + + if (!pressed && M5.Touch.ispressed()) + { + Serial.println("Pressed"); + penalties += penaltyAmount; + pressed = true; + } + else if (pressed && !M5.Touch.ispressed()) + { + pressed = false; + } +} + +void displayTime(unsigned long minutes, unsigned long seconds) +{ + M5.Lcd.setCursor(75, 50); + M5.Lcd.setTextColor(TFT_WHITE); + M5.Lcd.setTextSize(100); + M5.Lcd.printf("%02d:%02d", minutes, seconds); +} + +void turnScreenRed() +{ + M5.Lcd.fillScreen(TFT_RED); +}