main.ino 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <TFT_eSPI.h>
  2. #include "config.h"
  3. #include "display.h"
  4. static TFT_eSPI tft = TFT_eSPI();
  5. static bool lastSelectState = false;
  6. static bool screenBlanked = false;
  7. static unsigned long sysAStartMs = 0;
  8. // ---------------------------------------------------------------------------
  9. // Show the correct screen for the current input state
  10. // ---------------------------------------------------------------------------
  11. static void applyState(bool sysSelect) {
  12. screenBlanked = false;
  13. if (sysSelect) {
  14. // System A — show screen and start the blank timer
  15. displayShowSystemA(tft);
  16. sysAStartMs = millis();
  17. } else {
  18. // System B — show screen, no blank timer
  19. displayShowSystemB(tft);
  20. }
  21. }
  22. void setup() {
  23. // Internal pull-up: pin floating defaults to HIGH = System A
  24. pinMode(PIN_SYS_SELECT, INPUT_PULLUP);
  25. displayInit(tft);
  26. displayShowLogo(tft);
  27. displayShowSplash(tft);
  28. lastSelectState = digitalRead(PIN_SYS_SELECT);
  29. applyState(lastSelectState);
  30. }
  31. void loop() {
  32. bool state = digitalRead(PIN_SYS_SELECT);
  33. if (state != lastSelectState) {
  34. lastSelectState = state;
  35. applyState(state);
  36. }
  37. // Blank screen after timeout when sitting on System A
  38. if (lastSelectState && !screenBlanked) {
  39. if (millis() - sysAStartMs >= BLANK_TIMEOUT_MS) {
  40. displayBlank(tft);
  41. screenBlanked = true;
  42. }
  43. }
  44. delay(POLL_INTERVAL_MS);
  45. }