This commit is contained in:
BOT Alex 2024-05-15 13:41:20 +02:00
parent 5e214b6852
commit 55f94cd2d0
3 changed files with 76 additions and 2 deletions

View File

@ -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);

View File

@ -1,4 +1,4 @@
#include <M5StickCPlus.h>
#include <M5StickCPlus2.h>
#include "InputSystem.h"
#include "MathSystem.h"

View File

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