v.0.0.9 drawHorizontalScrollText
This commit is contained in:
@@ -31,7 +31,7 @@ uint8_t LedMatrix::charWidth(const uint8_t *charMatrix)
|
||||
// bei 8 -> 32-28 = 4.Bit
|
||||
// bei 2 -> 32-20 = 2.Bit
|
||||
|
||||
Serial.printf("max_val: [0x%04X] -> %d\n\r", max_val, (32 - __builtin_clz(max_val)));
|
||||
// Serial.printf("max_val: [0x%04X] -> %d\n\r", max_val, (32 - __builtin_clz(max_val)));
|
||||
|
||||
return (max_val == 0) ? 0 : (32 - __builtin_clz(max_val));
|
||||
}
|
||||
@@ -88,3 +88,60 @@ void LedMatrix::drawText(int x, int y, const char *text, CRGB color)
|
||||
cursorX += (chr_width + 1); // 5 pixels width + 1 pixel spacing
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t LedMatrix::getTextWidth(const char *text)
|
||||
{
|
||||
uint8_t totalWidth = 0;
|
||||
for (uint8_t i = 0; text[i] != '\0'; i++)
|
||||
{
|
||||
const uint8_t *fontData = getFontChar_5x7(text[i]);
|
||||
totalWidth += charWidth<7>(fontData) + 1; // char width + spacing
|
||||
}
|
||||
return totalWidth;
|
||||
}
|
||||
|
||||
void LedMatrix::clearRow(uint8_t y)
|
||||
{
|
||||
const u_int8_t font_height = fontHeight_5x7();
|
||||
|
||||
Serial.printf("clearRow: %dx%d@%d\n\r", font_height, width, y);
|
||||
|
||||
for (uint8_t line = y; line < (y + font_height); line++)
|
||||
{
|
||||
Serial.printf("\tline: %d\n\r", line);
|
||||
for (uint8_t x = 0; x < width; x++)
|
||||
{
|
||||
drawPixel(x, line, CRGB::Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LedMatrix::drawHorizontalScrollText(uint8_t y, const char *text, CRGB color, uint8_t scrollSpeed)
|
||||
{
|
||||
unsigned long currentTime = millis();
|
||||
uint8_t txtWidth = getTextWidth(text);
|
||||
|
||||
// Update scroll position based on time
|
||||
if (currentTime - lastScrollTime > scrollSpeed)
|
||||
{
|
||||
scrollPosition--;
|
||||
lastScrollTime = currentTime;
|
||||
|
||||
// Reset when text has completely scrolled off screen
|
||||
if (scrollPosition < -txtWidth)
|
||||
{
|
||||
scrollPosition = width;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the row where text will be drawn
|
||||
clearRow(y);
|
||||
|
||||
// Draw text at current scroll position
|
||||
drawText(scrollPosition, y, text, color);
|
||||
|
||||
show();
|
||||
|
||||
// Serial.printf("drawHorizontalScrollText: %s @[%d; %d]", text, scrollPosition, y);
|
||||
// Serial.println();
|
||||
}
|
||||
@@ -24,6 +24,12 @@ private:
|
||||
template <size_t N>
|
||||
uint8_t charWidth(const uint8_t *charMatrix);
|
||||
|
||||
// Text Scrolling
|
||||
int8_t scrollPosition = 0;
|
||||
unsigned long lastScrollTime = 0;
|
||||
|
||||
uint8_t getTextWidth(const char *text);
|
||||
|
||||
public:
|
||||
LedMatrix(uint8_t h = 64, uint8_t w = 64);
|
||||
|
||||
@@ -31,8 +37,13 @@ public:
|
||||
|
||||
void drawPixel(int x, int y, CRGB color);
|
||||
uint8_t drawChar(int x, int y, char c, CRGB color);
|
||||
|
||||
void clearRow(uint8_t y);
|
||||
|
||||
// Draw text string
|
||||
void drawText(int x, int y, const char *text, CRGB color);
|
||||
|
||||
void drawHorizontalScrollText(uint8_t y, const char *text, CRGB color, uint8_t scrollSpeed = 100);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "mathematics.h"
|
||||
|
||||
vector<uint16_t> number_to_bitarray_msb(u_int16_t number, int bits, boolean four_bits)
|
||||
vector<uint16_t> number_to_bitarray_msb(uint16_t number, int bits, boolean four_bits)
|
||||
{
|
||||
Serial.printf("s-o-n: %d", sizeof(number));
|
||||
Serial.println();
|
||||
@@ -27,4 +27,4 @@ vector<uint16_t> number_to_bitarray_msb(u_int16_t number, int bits, boolean four
|
||||
Serial.println();
|
||||
|
||||
return two_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user