From 156ce19ec69104f8b5ff71a4595dc2664462bf80 Mon Sep 17 00:00:00 2001 From: tiijay Date: Mon, 3 Nov 2025 15:19:04 +0100 Subject: [PATCH] v.0.0.1 setup Serial output --- lib/LedMatrix/src/LedMatrix.cpp | 42 ++++++++++++++++++++++++++++++++- lib/LedMatrix/src/LedMatrix.h | 37 +++-------------------------- src/main.cpp | 8 +++++++ 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/lib/LedMatrix/src/LedMatrix.cpp b/lib/LedMatrix/src/LedMatrix.cpp index 3761d31..158e8b3 100644 --- a/lib/LedMatrix/src/LedMatrix.cpp +++ b/lib/LedMatrix/src/LedMatrix.cpp @@ -8,4 +8,44 @@ LedMatrix::LedMatrix(uint8_t h, uint8_t w) LedMatrix::~LedMatrix() { -} \ No newline at end of file +} + +void LedMatrix::drawPixel(int x, int y, CRGB color) +{ + if (x >= 0 && x < 64 && y >= 0 && y < 64) + { + int index = y * 64 + x; // Row-major order + leds[index] = color; + } +} + +void LedMatrix::drawChar(int x, int y, char c, CRGB color) +{ + const uint8_t *fontData = getFontChar(c); + for (int row = 0; row < 7; row++) + { + uint8_t line = fontData[row]; + for (int col = 0; col < 5; col++) + { + if (line & (1 << (4 - col))) + { + drawPixel(x + col, y + row, color); + } + } + } +} + +// Draw text string +void LedMatrix::drawText(int x, int y, const char *text, CRGB color) +{ + int cursorX = x; + for (int i = 0; text[i] != '\0'; i++) + { + u_int8_t w = getCharWidth(text[i]); + // Debug output + Serial.printf("Char %d: '%c' -> width %d at X=%d\n\r", + i, text[i], w, cursorX); + drawChar(cursorX, y, text[i], color); + cursorX += 6; // 5 pixels width + 1 pixel spacing + } +} diff --git a/lib/LedMatrix/src/LedMatrix.h b/lib/LedMatrix/src/LedMatrix.h index e68e4cc..5d98f34 100644 --- a/lib/LedMatrix/src/LedMatrix.h +++ b/lib/LedMatrix/src/LedMatrix.h @@ -24,41 +24,10 @@ public: ~LedMatrix(); - void drawPixel(int x, int y, CRGB color) - { - if (x >= 0 && x < 64 && y >= 0 && y < 64) - { - int index = y * 64 + x; // Row-major order - leds[index] = color; - } - } - - void drawChar(int x, int y, char c, CRGB color) - { - const uint8_t *fontData = getFontChar(c); - for (int row = 0; row < 7; row++) - { - uint8_t line = fontData[row]; - for (int col = 0; col < 5; col++) - { - if (line & (1 << (4 - col))) - { - drawPixel(x + col, y + row, color); - } - } - } - } - + void drawPixel(int x, int y, CRGB color); + void drawChar(int x, int y, char c, CRGB color); // Draw text string - void drawText(int x, int y, const char *text, CRGB color) - { - int cursorX = x; - for (int i = 0; text[i] != '\0'; i++) - { - drawChar(cursorX, y, text[i], color); - cursorX += 6; // 5 pixels width + 1 pixel spacing - } - } + void drawText(int x, int y, const char *text, CRGB color); }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5611d0f..41bcd6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,14 @@ void playWithBlinkLed() void setup() { + // Initialize Serial for debug output + Serial.begin(115200); + + // Wait for Serial to be ready (important for some boards) + while (!Serial) + { + delay(10); + } matrix.setBrightness(255); matrix.clear();