v.0.0.8 mv number_to_bitarray_msb in utils-mathematics
This commit is contained in:
@@ -12,7 +12,7 @@ LedMatrix::~LedMatrix()
|
|||||||
|
|
||||||
// N entspricht Font-Height
|
// N entspricht Font-Height
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
uint8_t LedMatrix::charWidth(const uint16_t *charMatrix)
|
uint8_t LedMatrix::charWidth(const uint8_t *charMatrix)
|
||||||
{
|
{
|
||||||
uint16_t max_val = 0;
|
uint16_t max_val = 0;
|
||||||
for (size_t i = 0; i < N; i++)
|
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)
|
uint8_t LedMatrix::drawChar(int x, int y, char c, CRGB color)
|
||||||
{
|
{
|
||||||
const uint16_t *fontData = getFontChar_16x16(c);
|
const uint8_t *fontData = getFontChar_5x7(c);
|
||||||
const u_int8_t char_width_pixel = charWidth<16>(fontData);
|
const u_int8_t char_width_pixel = charWidth<7>(fontData);
|
||||||
const u_int8_t font_height = fontHeight_16x16();
|
const u_int8_t font_height = fontHeight_5x7();
|
||||||
const u_int8_t font_width = 16;
|
const u_int8_t font_width = 5;
|
||||||
|
|
||||||
for (u_int8_t row = 0; row < font_height; row++)
|
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
|
cursorX += (chr_width + 1); // 5 pixels width + 1 pixel spacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<uint16_t> 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<uint16_t> 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;
|
|
||||||
}
|
|
||||||
@@ -7,9 +7,9 @@ using namespace std;
|
|||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// #include <font_5x7.h>
|
#include <font_5x7.h>
|
||||||
// #include <font_8x8.h>
|
// #include <font_8x8.h>
|
||||||
#include <font_16x16.h>
|
// #include <font_16x16.h>
|
||||||
|
|
||||||
class LedMatrix : public CFastLED
|
class LedMatrix : public CFastLED
|
||||||
{
|
{
|
||||||
@@ -22,7 +22,7 @@ private:
|
|||||||
vector<CRGB> leds; // Automatic memory management
|
vector<CRGB> leds; // Automatic memory management
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
uint8_t charWidth(const uint16_t *charMatrix);
|
uint8_t charWidth(const uint8_t *charMatrix);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LedMatrix(uint8_t h = 64, uint8_t w = 64);
|
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);
|
uint8_t drawChar(int x, int y, char c, CRGB color);
|
||||||
// Draw text string
|
// Draw text string
|
||||||
void drawText(int x, int y, const char *text, CRGB color);
|
void drawText(int x, int y, const char *text, CRGB color);
|
||||||
|
|
||||||
vector<uint16_t> number_to_bitarray_msb(uint16_t number, int bits = 8, boolean four_bits = false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
7
lib/Utils/library.json
Normal file
7
lib/Utils/library.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
30
lib/Utils/src/mathematics.cpp
Normal file
30
lib/Utils/src/mathematics.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "mathematics.h"
|
||||||
|
|
||||||
|
vector<uint16_t> 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<uint16_t> 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;
|
||||||
|
}
|
||||||
11
lib/Utils/src/mathematics.h
Normal file
11
lib/Utils/src/mathematics.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef MATHEMATICS_H
|
||||||
|
#define MATHEMATICS_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
vector<uint16_t> number_to_bitarray_msb(uint16_t number, int bits = 16, boolean four_bits = false);
|
||||||
|
|
||||||
|
#endif
|
||||||
20
src/main.cpp
20
src/main.cpp
@@ -2,14 +2,15 @@
|
|||||||
#include <MyClass.h>
|
#include <MyClass.h>
|
||||||
#include <BlinkInternLed.h>
|
#include <BlinkInternLed.h>
|
||||||
#include <LedMatrix.h>
|
#include <LedMatrix.h>
|
||||||
|
#include <mathematics.h>
|
||||||
|
|
||||||
LedMatrix matrix;
|
LedMatrix matrix;
|
||||||
|
|
||||||
void printCharMatrixSimple(char c)
|
void printCharMatrixSimple(char c)
|
||||||
{
|
{
|
||||||
const uint16_t *fontData = getFontChar_16x16(c);
|
const auto *fontData = getFontChar_5x7(c);
|
||||||
const u_int8_t char_width_pixel = 16;
|
const u_int8_t char_width_pixel = 5;
|
||||||
const u_int8_t font_height = fontHeight_16x16();
|
const u_int8_t font_height = fontHeight_5x7();
|
||||||
|
|
||||||
Serial.print("<");
|
Serial.print("<");
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
@@ -19,7 +20,6 @@ void printCharMatrixSimple(char c)
|
|||||||
for (int row = 0; row < font_height; row++)
|
for (int row = 0; row < font_height; row++)
|
||||||
{
|
{
|
||||||
uint16_t line = fontData[row];
|
uint16_t line = fontData[row];
|
||||||
matrix.number_to_bitarray_msb(line, 16);
|
|
||||||
|
|
||||||
for (int col = 0; col < char_width_pixel; col++)
|
for (int col = 0; col < char_width_pixel; col++)
|
||||||
{
|
{
|
||||||
@@ -62,10 +62,10 @@ void playWithMatrix()
|
|||||||
matrix.show();
|
matrix.show();
|
||||||
|
|
||||||
// Draw static "HELLO WORLD"
|
// Draw static "HELLO WORLD"
|
||||||
// matrix.drawText(1, 1, "Hello World!", CRGB::Red);
|
matrix.drawText(1, 1, "Hello World!", CRGB::Red);
|
||||||
// matrix.drawText(1, 9, "<°|`¶>", CRGB::Yellow);
|
matrix.drawText(1, 9, "<°|`¶>", CRGB::Yellow);
|
||||||
// matrix.drawText(1, 17, "Bottom", CRGB::Yellow);
|
matrix.drawText(1, 17, "Bottom", CRGB::Yellow);
|
||||||
// matrix.drawText(1, 25, "ABCDEFGHIJ.", CRGB::Yellow);
|
matrix.drawText(1, 25, "ABCDEFGHIJ.", CRGB::Yellow);
|
||||||
matrix.drawText(1, 33, "A", CRGB::Yellow);
|
matrix.drawText(1, 33, "A", CRGB::Yellow);
|
||||||
matrix.show();
|
matrix.show();
|
||||||
}
|
}
|
||||||
@@ -81,9 +81,9 @@ void setup()
|
|||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
playWithMatrix();
|
// playWithMatrix();
|
||||||
printCharMatrixSimple('A');
|
printCharMatrixSimple('A');
|
||||||
// matrix.number_to_bitarray_msb(0x8F);
|
number_to_bitarray_msb(0x11FF, 16, true);
|
||||||
|
|
||||||
// playWithBlinkLed();
|
// playWithBlinkLed();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user