54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#include <FastLED.h>
|
|
#include "LEDMatrix.h"
|
|
#include "font.h"
|
|
|
|
// Params for width and height
|
|
const uint8_t kMatrixWidth = 32;
|
|
const uint8_t kMatrixHeight = 16;
|
|
|
|
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
|
|
#define DATA_PIN D2
|
|
#define LAST_VISIBLE_LED 511
|
|
|
|
CRGB leds[NUM_LEDS];
|
|
LEDMatrix matrix(kMatrixWidth, kMatrixHeight, NUM_LEDS, LAST_VISIBLE_LED, leds);
|
|
|
|
void setup() {
|
|
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
|
|
FastLED.setBrightness(40);
|
|
FastLED.clear();
|
|
FastLED.show();
|
|
}
|
|
|
|
void drawChar(char c, int x, int y, CRGB color) {
|
|
if (c < 32 || c > 127) return; // Ignore non-printable characters
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
uint8_t line = font[(c - 32) * 5 + i]; // Access the font array as a one-dimensional array
|
|
for (int j = 0; j < 7; j++) {
|
|
if (line & 0x1) {
|
|
matrix.drawPixel(x + i, y + j, color);
|
|
}
|
|
line >>= 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO: Fix letter overflow
|
|
void drawText(const char* text, int x, int y, CRGB color) {
|
|
while (*text) {
|
|
drawChar(*text++, x, y, color);
|
|
x += 6; // Move to the next character position
|
|
if (x >= kMatrixWidth) { // Handle overflow to the next screen
|
|
x = 0;
|
|
y += 8; // Move to the next line
|
|
}
|
|
}
|
|
}
|
|
|
|
void loop() {
|
|
FastLED.clear();
|
|
drawText("abwawawawaa", 0, 0, CRGB::White);
|
|
FastLED.show();
|
|
delay(1000);
|
|
} |