#include <FastLED.h>
#define NUM_LEDS 48 // 3 * 16 = 48 LEDs in total
#define DATA_PIN 6 // Pin connected to the data line of the LEDs
CRGB leds[NUM_LEDS];
const int matrixWidth = 3;
const int matrixHeight = 16;
// 3x5 font for characters 32-127 (printable ASCII)
const byte font[96][3] = {
{0,0,0}, // space
{0,95,0}, // !
{7,0,7}, // "
{31,10,31}, // #
{18,63,9}, // $
{3,24,0}, // %
{31,21,10}, // &
{0,7,0}, // '
{14,17,0}, // (
{17,14,0}, // )
{10,31,10}, // *
{4,14,4}, // +
{16,8,0}, // ,
{4,4,4}, // -
{0,16,0}, // .
{8,4,2}, // /
{31,17,31}, // 0
{18,31,16}, // 1
{29,21,23}, // 2
{21,21,31}, // 3
{7,4,31}, // 4
{23,21,29}, // 5
{31,21,29}, // 6
{1,1,31}, // 7
{31,21,31}, // 8
{23,21,31}, // 9
{0,10,0}, // :
{16,10,0}, // ;
{4,10,17}, // <
{10,10,10}, // =
{17,10,4}, // >
{1,21,3}, // ?
{30,37,22}, // @
{30,5,30}, // A
{31,21,10}, // B
{14,17,17}, // C
{31,17,14}, // D
{31,21,21}, // E
{31,5,5}, // F
{14,21,29}, // G
{31,4,31}, // H
{17,31,17}, // I
{8,16,15}, // J
{31,4,27}, // K
{31,16,16}, // L
{31,2,31}, // M
{31,6,31}, // N
{14,17,14}, // O
{31,5,2}, // P
{14,17,30}, // Q
{31,13,18}, // R
{18,21,9}, // S
{1,31,1}, // T
{15,16,15}, // U
{7,24,7}, // V
{31,12,31}, // W
{27,4,27}, // X
{3,28,3}, // Y
{25,21,19}, // Z
{31,17,0}, // [
{2,4,8}, // backslash
{17,31,0}, // ]
{2,1,2}, // ^
{16,16,16}, // _
{1,2,0}, // `
{24,20,28}, // a
{31,20,8}, // b
{8,20,20}, // c
{8,20,31}, // d
{14,26,10}, // e
{4,30,5}, // f
{10,21,15}, // g
{31,4,24}, // h
{29,0,0}, // i
{16,29,0}, // j
{31,4,26}, // k
{16,31,0}, // l
{28,4,28}, // m
{28,4,24}, // n
{8,20,8}, // o
{31,10,4}, // p
{4,10,31}, // q
{28,4,4}, // r
{8,21,2}, // s
{4,30,20}, // t
{12,16,28}, // u
{12,16,12}, // v
{28,8,28}, // w
{20,8,20}, // x
{10,20,30}, // y
{18,26,20}, // z
{4,14,17}, // {
{31,0,0}, // |
{17,14,4}, // }
{2,1,2} // ~
};
int XY(int x, int y) {
if (x < 0 || x >= matrixWidth || y < 0 || y >= matrixHeight) {
return -1; // Out of bounds
}
if (y % 2 == 0) {
return (y * matrixWidth) + x; // Even rows left to right
} else {
return (y * matrixWidth) + (matrixWidth - 1 - x); // Odd rows right to left
}
}
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
}
void loop() {
char message[] = "P A U L";
int messageLength = strlen(message);
for (int offset = 0; offset < messageLength * 5 + matrixHeight; offset++) {
FastLED.clear();
for (int i = 0; i < messageLength; i++) {
displayCharacter(message[i], offset - i * 5);
}
FastLED.show();
delay(100); // Adjust scrolling speed here
}
}
void displayCharacter(char c, int yOffset) {
if (c < 32 || c > 127) {
return; // Character out of range
}
byte charIndex = c - 32;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 5; y++) {
if (y + yOffset >= 0 && y + yOffset < matrixHeight) {
if (font[charIndex][2 - x] & (1 << (4 - y))) { // Flipping the character
int ledIndex = XY(x, y + yOffset);
if (ledIndex != -1) {
leds[ledIndex] = CRGB(0, 255, 13); // Set the LED color here
}
}
}
}
}
}