From 67a676c320e06bbd26c1a2de5f217095f08ea758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Thu, 7 Aug 2025 11:04:23 +0200 Subject: [PATCH] code clean --- src/beep.h | 6 ++++-- src/main.cpp | 32 ++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/beep.h b/src/beep.h index fb6270f..0482625 100644 --- a/src/beep.h +++ b/src/beep.h @@ -3,12 +3,14 @@ #include +#define BEEP_PIN 2 + inline void beepSet(const bool state) { - digitalWrite(2, state ? HIGH : LOW); + digitalWrite(BEEP_PIN, state ? HIGH : LOW); } inline void beepSetup() { - pinMode(2,OUTPUT); + pinMode(BEEP_PIN,OUTPUT); beepSet(false); } diff --git a/src/main.cpp b/src/main.cpp index ac1173a..43450df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,19 +3,16 @@ #include "mode/Mode.h" #include "mode/ModeTimer.h" +void stepMode(); + +void readConsole(); + +void buttonCallback(ButtonEvent event); + Display display; ModeTimer mode; -void buttonCallback(const ButtonEvent event) { - if (event == BUTTON_PRESSED) { - mode.buttonOK(); - } - if (BUTTON_PRESSED_LONG) { - mode.buttonESC(); - } -} - Button button(23, buttonCallback); void setup() { @@ -29,14 +26,20 @@ void setup() { } void loop() { + stepMode(); + readConsole(); +} + +void stepMode() { const uint64_t now = millis(); static uint64_t lastMillis = 0; const uint64_t deltaMillis = now - lastMillis; lastMillis = now; - mode.step(deltaMillis); mode.draw(display); +} +void readConsole() { const auto code = Serial.read(); if (code == ' ') { mode.buttonOK(); @@ -45,3 +48,12 @@ void loop() { mode.buttonESC(); } } + +void buttonCallback(const ButtonEvent event) { + if (event == BUTTON_PRESSED) { + mode.buttonOK(); + } + if (BUTTON_PRESSED_LONG) { + mode.buttonESC(); + } +}