first commit

This commit is contained in:
tiijay
2025-11-03 15:05:22 +01:00
commit 941c168de8
24 changed files with 728 additions and 0 deletions

View 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"
}

View File

@@ -0,0 +1,11 @@
#include "LedMatrix.h"
LedMatrix::LedMatrix(uint8_t h, uint8_t w)
: height(h), width(w), num_leds(h * w), leds(num_leds)
{
addLeds<WS2812B, MATRIX_PIN, RGB>(leds.data(), num_leds);
}
LedMatrix::~LedMatrix()
{
}

View 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