v.0.0.2 number_to_bitarray_msb
This commit is contained in:
@@ -18,7 +18,6 @@ uint8_t getCharWidth(char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'I':
|
||||
case '!':
|
||||
case '.':
|
||||
case ':':
|
||||
@@ -26,10 +25,10 @@ uint8_t getCharWidth(char c)
|
||||
case '\'':
|
||||
case '|':
|
||||
return 1;
|
||||
case 'i':
|
||||
case ' ':
|
||||
return 2;
|
||||
case 'J':
|
||||
case 'I':
|
||||
case 'i':
|
||||
case 'j':
|
||||
case 'l':
|
||||
case '(':
|
||||
|
||||
@@ -21,12 +21,16 @@ void LedMatrix::drawPixel(int x, int y, CRGB color)
|
||||
|
||||
void LedMatrix::drawChar(int x, int y, char c, CRGB color)
|
||||
{
|
||||
u_int8_t char_width_pixel = getCharWidth(c);
|
||||
// Serial.printf("Char '%c' -> width %d\n\r", c, char_width_pixel);
|
||||
|
||||
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++)
|
||||
for (int col = 0; col < 5 /*char_width_pixel*/; col++)
|
||||
{
|
||||
drawPixel(x + col, y + row, CRGB::SlateGrey);
|
||||
if (line & (1 << (4 - col)))
|
||||
{
|
||||
drawPixel(x + col, y + row, color);
|
||||
@@ -35,17 +39,60 @@ void LedMatrix::drawChar(int x, int y, char c, CRGB color)
|
||||
}
|
||||
}
|
||||
|
||||
void LedMatrix::_drawChar_(int x, int y, char c, CRGB color)
|
||||
{
|
||||
u_int8_t char_width_pixel = getCharWidth(c);
|
||||
// Serial.printf("Char '%c' -> width %d\n\r", c, char_width_pixel);
|
||||
|
||||
const uint8_t *fontData = getFontChar(c);
|
||||
for (int row = 0; row < 7; row++)
|
||||
{
|
||||
uint8_t line = fontData[row];
|
||||
for (int col = 5 - char_width_pixel; col < 5; col++)
|
||||
{
|
||||
drawPixel(x + col, y + row, CRGB::SlateGrey);
|
||||
if (line & (1 << (4 - col)))
|
||||
{
|
||||
drawPixel(x + col, y + row, CRGB::GhostWhite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
_drawChar_(cursorX, 8 + y, text[i], color);
|
||||
cursorX += 6; // 5 pixels width + 1 pixel spacing
|
||||
}
|
||||
}
|
||||
|
||||
vector<uint8_t> LedMatrix::number_to_bitarray_msb(uint16_t number, int bits)
|
||||
{
|
||||
/** Convert 8/16-bit number to bit array (MSB first) */
|
||||
std::vector<uint8_t> byte;
|
||||
byte.reserve(bits);
|
||||
|
||||
for (int i = bits - 1; i >= 0; i--)
|
||||
{
|
||||
byte.push_back((number >> i) & 1);
|
||||
}
|
||||
|
||||
// Debug, Ausgabe des Bytes
|
||||
Serial.printf("0x%02X\n\r", number);
|
||||
uint8_t idx = 0;
|
||||
for (auto bit : byte)
|
||||
{
|
||||
Serial.printf("%d", bit);
|
||||
idx++;
|
||||
if (!(idx % 4))
|
||||
Serial.printf(" ");
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
return byte;
|
||||
}
|
||||
@@ -26,8 +26,11 @@ public:
|
||||
|
||||
void drawPixel(int x, int y, CRGB color);
|
||||
void drawChar(int x, int y, char c, 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);
|
||||
|
||||
vector<uint8_t> number_to_bitarray_msb(uint16_t number, int bits = 8);
|
||||
};
|
||||
|
||||
#endif
|
||||
20
src/main.cpp
20
src/main.cpp
@@ -10,10 +10,9 @@ void printCharMatrixSimple(char c)
|
||||
{
|
||||
const uint8_t *fontData = getFontChar(c);
|
||||
|
||||
Serial.println();
|
||||
Serial.print("'");
|
||||
Serial.print("<");
|
||||
Serial.print(c);
|
||||
Serial.println("':");
|
||||
Serial.println(">");
|
||||
|
||||
String mtrx = "";
|
||||
for (int row = 0; row < 7; row++)
|
||||
@@ -24,16 +23,13 @@ void printCharMatrixSimple(char c)
|
||||
if (line & (1 << (4 - col)))
|
||||
{
|
||||
mtrx += "•";
|
||||
Serial.print("#"); // Einfaches # für Pixel
|
||||
}
|
||||
else
|
||||
{
|
||||
mtrx += ".";
|
||||
Serial.print("."); // Punkt für leere Pixel
|
||||
}
|
||||
}
|
||||
mtrx += "\n\r";
|
||||
Serial.println();
|
||||
}
|
||||
Serial.println(mtrx);
|
||||
}
|
||||
@@ -71,13 +67,15 @@ void setup()
|
||||
matrix.show();
|
||||
|
||||
// Draw static "HELLO WORLD"
|
||||
matrix.drawText(1, 1, "Hello", CRGB::Red);
|
||||
matrix.drawText(35, 1, "World", CRGB::Blue);
|
||||
matrix.drawText(1, 20, "<°|`¶>", CRGB::Yellow);
|
||||
matrix.drawText(1, 30, "Bottom", CRGB::Yellow);
|
||||
// matrix.drawText(1, 1, "Hello", CRGB::Red);
|
||||
// matrix.drawText(35, 1, "World", CRGB::Blue);
|
||||
// matrix.drawText(1, 20, "<°|`¶>", CRGB::Yellow);
|
||||
// matrix.drawText(1, 30, "Bottom", CRGB::Yellow);
|
||||
matrix.drawText(1, 40, "ABCDEFGHIJ.", CRGB::Yellow);
|
||||
matrix.show();
|
||||
|
||||
// printCharMatrixSimple('S');
|
||||
printCharMatrixSimple('S');
|
||||
matrix.number_to_bitarray_msb(0x8F);
|
||||
|
||||
// playWithBlinkLed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user