first commit
This commit is contained in:
64
lib/LedMatrix/src/LedMatrix.h
Normal file
64
lib/LedMatrix/src/LedMatrix.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef LEDMATRIX
|
||||
#define LEDMATRIX
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <FastLED.h>
|
||||
#include <vector>
|
||||
|
||||
#include <font_5x7.h>
|
||||
|
||||
class LedMatrix : public CFastLED
|
||||
{
|
||||
private:
|
||||
uint8_t height;
|
||||
uint8_t width;
|
||||
|
||||
static const uint8_t MATRIX_PIN = 28;
|
||||
uint16_t num_leds; // default 64x64 = 4096 LEDs
|
||||
vector<CRGB> leds; // Automatic memory management
|
||||
|
||||
public:
|
||||
LedMatrix(uint8_t h = 64, uint8_t w = 64);
|
||||
|
||||
~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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user