v.0.0.1 setup Serial output

This commit is contained in:
tiijay
2025-11-03 15:19:04 +01:00
parent 941c168de8
commit 156ce19ec6
3 changed files with 52 additions and 35 deletions

View File

@@ -9,3 +9,43 @@ LedMatrix::LedMatrix(uint8_t h, uint8_t w)
LedMatrix::~LedMatrix()
{
}
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
}
}

View File

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

View File

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