diff --git a/src/Color.cpp b/src/Color.cpp index c1c1add..d683d47 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -1,13 +1,14 @@ #include "Color.h" #define ___ 0 +#define QQQ 64 #define TTT 85 #define HHH 127 #define XXX 255 // @formatter:off Color RED (XXX, ___, ___); -Color YELLOW (HHH, HHH, ___); +Color YELLOW (HHH, QQQ, ___); Color GREEN (___, XXX, ___); Color TURQUOISE (___, HHH, HHH); Color BLUE (___, ___, XXX); diff --git a/src/display.cpp b/src/display.cpp index 77a9d26..af40895 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -20,6 +20,7 @@ uint8_t CHARS[] = { 0b11100110, // P 0b11110110, // A 0b10111100, // U + 0b00000010, // - }; int toIndex(char c) { @@ -29,6 +30,14 @@ int toIndex(char c) { switch (c) { case 'P': return 10; + case 'A': + return 11; + case 'U': + return 12; + case 'S': + return 5; + case '-': + return 13; } return -1; } @@ -41,17 +50,19 @@ uint8_t mapChar(char c) { return 0; } -void drawChar(Adafruit_NeoPixel& pixels, int digit, char c, bool showIfZero, Color& color) { +void drawChar(Adafruit_NeoPixel& pixels, int digit, char c, const Color& color) { + drawChar(pixels, digit, c, true, color); +} + +void drawChar(Adafruit_NeoPixel& pixels, int digit, char c, bool showIfZero, const Color& color) { if (c == '0' && !showIfZero) { return; } auto pixel = digit * SEGMENTS_PER_DIGIT * LEDS_PER_SEGMENT + (digit > DOTS_AFTER_DIGIT ? DOT_COUNT * LEDS_PER_DOT : 0); const auto symbol = mapChar(c); - Serial.printf(" character '%c'\n", c); uint8_t symbolMask = 128; for (int segment = 0; segment < SEGMENTS_PER_DIGIT; ++segment) { const auto on = (symbol & symbolMask) != 0; - Serial.printf(" segment %d = %s\n", segment, on ? "ON" : "__"); if (on) { for (int led = 0; led < LEDS_PER_SEGMENT; ++led) { pixels.setPixelColor(pixel, color.r, color.g, color.b); @@ -64,7 +75,7 @@ void drawChar(Adafruit_NeoPixel& pixels, int digit, char c, bool showIfZero, Col } } -void drawNumber(Adafruit_NeoPixel& pixels, int digit, int number, bool zero, Color& color) { +void drawNumber(Adafruit_NeoPixel& pixels, int digit, int number, bool zero, const Color& color) { const char ten = '0' + (number / 10 % 10); const char one = '0' + (number % 10); drawChar(pixels, digit + 0, ten, zero, color); @@ -73,13 +84,46 @@ void drawNumber(Adafruit_NeoPixel& pixels, int digit, int number, bool zero, Col void drawDot(Adafruit_NeoPixel& pixels, int dot, const Color& c) { int index = 2 * SEGMENTS_PER_DIGIT * LEDS_PER_SEGMENT + dot * LEDS_PER_DOT; - pixels.setPixelColor(index++, c.r, c.g, c.b); - pixels.setPixelColor(index++, c.r, c.g, c.b); + pixels.setPixelColor(index + 0, c.r, c.g, c.b); + pixels.setPixelColor(index + 1, c.r, c.g, c.b); } -void drawDots(Adafruit_NeoPixel& pixels, Color& bottom, Color& middleBottom, Color& middleTop, Color& top) { +void drawDots(Adafruit_NeoPixel& pixels, const Color& bottom, const Color& middleBottom, const Color& middleTop, const Color& top) { drawDot(pixels, 0, bottom); drawDot(pixels, 1, middleBottom); drawDot(pixels, 2, middleTop); drawDot(pixels, 3, top); } + +void drawMillis(Adafruit_NeoPixel& pixels, const unsigned long millisTotal, const Color& color) { + const auto secondsTotal = millisTotal / 1000; + const auto minutes = (int) secondsTotal / 60; + const auto seconds = (int) secondsTotal % 60; + + if (minutes > 0) { + static auto lastSeconds = -1; + if (lastSeconds == seconds) { + return; + } + lastSeconds = seconds; + + Serial.printf("%2d:%02d\n", minutes, seconds); + + pixels.clear(); + drawNumber(pixels, 0, minutes, false, color); + drawDots(pixels, BLACK, color, color, BLACK); + drawNumber(pixels, 2, seconds, true, color); + pixels.show(); + } else { + const auto deci = (int) millisTotal / 100 % 10; + Serial.printf("%2d.%02d\n", seconds, deci); + + pixels.clear(); + if (seconds > 0) { + drawNumber(pixels, 0, seconds, false, color); + drawDots(pixels, color, BLACK, BLACK, BLACK); + } + drawChar(pixels, 2, '0' + deci, true, color); + pixels.show(); + } +} diff --git a/src/display.h b/src/display.h index e300baf..b2d00cf 100644 --- a/src/display.h +++ b/src/display.h @@ -5,10 +5,14 @@ #include "Color.h" -void drawChar(Adafruit_NeoPixel& pixels, int digit, char c, bool showIfZero, Color& color); +void drawChar(Adafruit_NeoPixel& pixels, int digit, char c, const Color& color); -void drawNumber(Adafruit_NeoPixel& pixels, int digit, int number, bool zero, Color& color); +void drawChar(Adafruit_NeoPixel& pixels, int digit, char c, bool showIfZero, const Color& color); -void drawDots(Adafruit_NeoPixel& pixels, Color& bottom, Color& middleBottom, Color& middleTop, Color& top); +void drawNumber(Adafruit_NeoPixel& pixels, int digit, int number, bool zero, const Color& color); + +void drawDots(Adafruit_NeoPixel& pixels, const Color& bottom, const Color& middleBottom, const Color& middleTop, const Color& top); + +void drawMillis(Adafruit_NeoPixel& pixels, unsigned long millisTotal, const Color& color); #endif diff --git a/src/main.cpp b/src/main.cpp index 6155788..142c29c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,9 +16,9 @@ void setup() { pixels.show(); } -long configCountdownSeconds = 65; +long configCountdownMillis = 6 * 60 * 1000; -long countdownRestMillis = configCountdownSeconds * 1000; +long rest = configCountdownMillis; unsigned long last = 0; @@ -26,32 +26,30 @@ void updateTime() { const auto now = max(1UL, millis()); if (last != 0) { const auto diff = now - last; - countdownRestMillis -= (long) diff; - if (countdownRestMillis < 0) { - countdownRestMillis = 0; + rest -= (long) diff; + if (rest < 0) { + rest = 0; } } last = now; } -void showTime() { - const auto secondsTotal = (unsigned long) ceil(countdownRestMillis / 1000.0); - const auto minutes = (int) secondsTotal / 60; - const auto seconds = (int) secondsTotal % 60; +bool running = true; - static auto lastSeconds = -1; - if (lastSeconds == seconds) { +void showTime() { + if (!running) { return; } - lastSeconds = seconds; - - Serial.printf("%2d:%02d\n", minutes, seconds); - - pixels.clear(); - drawNumber(pixels, 0, minutes, false, WHITE); - drawDots(pixels, BLACK, WHITE, WHITE, BLACK); - drawNumber(pixels, 2, seconds, true, WHITE); - pixels.show(); + if (rest > 0) { + const auto color = rest >= 60000 ? WHITE : (rest >= 10000 ? YELLOW : RED); + drawMillis(pixels, rest, color); + } else { + running = false; + pixels.clear(); + drawNumber(pixels, 3, 0, true, RED); + pixels.show(); + Serial.println("END"); + } } void loop() {