diff --git a/lib/LedMatrix/src/LedMatrix.cpp b/lib/LedMatrix/src/LedMatrix.cpp index ad38346..0f2904e 100644 --- a/lib/LedMatrix/src/LedMatrix.cpp +++ b/lib/LedMatrix/src/LedMatrix.cpp @@ -12,7 +12,7 @@ LedMatrix::~LedMatrix() // N entspricht Font-Height template -uint8_t LedMatrix::charWidth(const uint16_t *charMatrix) +uint8_t LedMatrix::charWidth(const uint8_t *charMatrix) { uint16_t max_val = 0; for (size_t i = 0; i < N; i++) @@ -47,10 +47,10 @@ void LedMatrix::drawPixel(int x, int y, CRGB color) uint8_t LedMatrix::drawChar(int x, int y, char c, CRGB color) { - const uint16_t *fontData = getFontChar_16x16(c); - const u_int8_t char_width_pixel = charWidth<16>(fontData); - const u_int8_t font_height = fontHeight_16x16(); - const u_int8_t font_width = 16; + const uint8_t *fontData = getFontChar_5x7(c); + const u_int8_t char_width_pixel = charWidth<7>(fontData); + const u_int8_t font_height = fontHeight_5x7(); + const u_int8_t font_width = 5; for (u_int8_t row = 0; row < font_height; row++) { @@ -88,29 +88,3 @@ void LedMatrix::drawText(int x, int y, const char *text, CRGB color) cursorX += (chr_width + 1); // 5 pixels width + 1 pixel spacing } } - -vector LedMatrix::number_to_bitarray_msb(uint16_t number, int bits, boolean four_bits) -{ - /** Convert 8/16-bit number to bit array (MSB first) */ - std::vector two_bytes; - two_bytes.reserve(bits); - - for (int i = bits - 1; i >= 0; i--) - { - two_bytes.push_back((number >> i) & 1); - } - - // Debug, Ausgabe des Bytes - Serial.printf("[0x%04X] ", number); - uint8_t idx = 0; - for (auto bit : two_bytes) - { - Serial.printf("%d", bit); - idx++; - if (four_bits && !(idx % 4)) - Serial.printf(" "); - } - Serial.println(); - - return two_bytes; -} \ No newline at end of file diff --git a/lib/LedMatrix/src/LedMatrix.h b/lib/LedMatrix/src/LedMatrix.h index c425b03..b1f7b33 100644 --- a/lib/LedMatrix/src/LedMatrix.h +++ b/lib/LedMatrix/src/LedMatrix.h @@ -7,9 +7,9 @@ using namespace std; #include #include -// #include +#include // #include -#include +// #include class LedMatrix : public CFastLED { @@ -22,7 +22,7 @@ private: vector leds; // Automatic memory management template - uint8_t charWidth(const uint16_t *charMatrix); + uint8_t charWidth(const uint8_t *charMatrix); public: LedMatrix(uint8_t h = 64, uint8_t w = 64); @@ -33,8 +33,6 @@ public: uint8_t drawChar(int x, int y, char c, CRGB color); // Draw text string void drawText(int x, int y, const char *text, CRGB color); - - vector number_to_bitarray_msb(uint16_t number, int bits = 8, boolean four_bits = false); }; #endif \ No newline at end of file diff --git a/lib/Utils/library.json b/lib/Utils/library.json new file mode 100644 index 0000000..7b6fd93 --- /dev/null +++ b/lib/Utils/library.json @@ -0,0 +1,7 @@ +{ + "name": "BlinkLed", + "version": "1.0.0", + "description": "A simple LED control library with internal LED helper.", + "authors": [{ "name": "TiiJay14" }], + "frameworks": "arduino" +} diff --git a/lib/Utils/src/mathematics.cpp b/lib/Utils/src/mathematics.cpp new file mode 100644 index 0000000..47ab657 --- /dev/null +++ b/lib/Utils/src/mathematics.cpp @@ -0,0 +1,30 @@ +#include "mathematics.h" + +vector number_to_bitarray_msb(u_int16_t number, int bits, boolean four_bits) +{ + Serial.printf("s-o-n: %d", sizeof(number)); + Serial.println(); + + /** Convert 8/16-bit number to bit array (MSB first) */ + std::vector two_bytes; + two_bytes.reserve(bits); + + for (int i = bits - 1; i >= 0; i--) + { + two_bytes.push_back((number >> i) & 1); + } + + // Debug, Ausgabe des Bytes + Serial.printf("[0x%04X] ", number); + uint8_t idx = 0; + for (auto bit : two_bytes) + { + Serial.printf("%d", bit); + idx++; + if (four_bits && !(idx % 4)) + Serial.printf(" "); + } + Serial.println(); + + return two_bytes; +} \ No newline at end of file diff --git a/lib/Utils/src/mathematics.h b/lib/Utils/src/mathematics.h new file mode 100644 index 0000000..207c28a --- /dev/null +++ b/lib/Utils/src/mathematics.h @@ -0,0 +1,11 @@ +#ifndef MATHEMATICS_H +#define MATHEMATICS_H + +#include +#include + +using namespace std; + +vector number_to_bitarray_msb(uint16_t number, int bits = 16, boolean four_bits = false); + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1263f92..9e5a130 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,14 +2,15 @@ #include #include #include +#include LedMatrix matrix; void printCharMatrixSimple(char c) { - const uint16_t *fontData = getFontChar_16x16(c); - const u_int8_t char_width_pixel = 16; - const u_int8_t font_height = fontHeight_16x16(); + const auto *fontData = getFontChar_5x7(c); + const u_int8_t char_width_pixel = 5; + const u_int8_t font_height = fontHeight_5x7(); Serial.print("<"); Serial.print(c); @@ -19,7 +20,6 @@ void printCharMatrixSimple(char c) for (int row = 0; row < font_height; row++) { uint16_t line = fontData[row]; - matrix.number_to_bitarray_msb(line, 16); for (int col = 0; col < char_width_pixel; col++) { @@ -62,10 +62,10 @@ void playWithMatrix() matrix.show(); // Draw static "HELLO WORLD" - // matrix.drawText(1, 1, "Hello World!", CRGB::Red); - // matrix.drawText(1, 9, "<°|`¶>", CRGB::Yellow); - // matrix.drawText(1, 17, "Bottom", CRGB::Yellow); - // matrix.drawText(1, 25, "ABCDEFGHIJ.", CRGB::Yellow); + matrix.drawText(1, 1, "Hello World!", CRGB::Red); + matrix.drawText(1, 9, "<°|`¶>", CRGB::Yellow); + matrix.drawText(1, 17, "Bottom", CRGB::Yellow); + matrix.drawText(1, 25, "ABCDEFGHIJ.", CRGB::Yellow); matrix.drawText(1, 33, "A", CRGB::Yellow); matrix.show(); } @@ -81,9 +81,9 @@ void setup() delay(10); } - playWithMatrix(); + // playWithMatrix(); printCharMatrixSimple('A'); - // matrix.number_to_bitarray_msb(0x8F); + number_to_bitarray_msb(0x11FF, 16, true); // playWithBlinkLed(); }