Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \#include <FastLED.h>
- // LED configuration
- \#define LED\_PIN 6
- \#define NUM\_LEDS 164 // 41 x 4
- \#define BRIGHTNESS 50
- \#define COLOR\_ORDER GRB
- CRGB leds\[NUM\_LEDS\];
- // Grid size
- \#define WIDTH 41
- \#define HEIGHT 4
- // Text settings
- const char\* text = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9";
- int scrollSpeed = 100; // Speed of scrolling (ms)
- // 4x5 font data (A-Z, 0-9, space)
- const uint8\_t font\[\]\[4\] = {
- {0b1110, 0b1001, 0b1001, 0b1110}, // A
- {0b1111, 0b1001, 0b1001, 0b0110}, // B
- {0b1110, 0b1000, 0b1000, 0b0110}, // C
- {0b1111, 0b1001, 0b1001, 0b1110}, // D
- {0b1111, 0b1000, 0b1000, 0b1000}, // E
- {0b1111, 0b1000, 0b1000, 0b1000}, // F
- {0b1110, 0b1000, 0b1001, 0b0111}, // G
- {0b1001, 0b1001, 0b1111, 0b1001}, // H
- {0b1111, 0b0010, 0b0010, 0b1111}, // I
- {0b0001, 0b0001, 0b0001, 0b1110}, // J
- {0b1001, 0b1010, 0b1100, 0b1000}, // K
- {0b1000, 0b1000, 0b1000, 0b1111}, // L
- {0b1001, 0b1101, 0b1011, 0b1001}, // M
- {0b1001, 0b1011, 0b1101, 0b1001}, // N
- {0b1110, 0b1001, 0b1001, 0b1110}, // O
- {0b1111, 0b1001, 0b1000, 0b1000}, // P
- {0b1110, 0b1001, 0b1001, 0b1110}, // Q
- {0b1111, 0b1001, 0b1000, 0b1100}, // R
- {0b1110, 0b1001, 0b0011, 0b1110}, // S
- {0b1111, 0b0010, 0b0010, 0b0010}, // T
- {0b1001, 0b1001, 0b1001, 0b0110}, // U
- {0b1001, 0b1001, 0b0100, 0b0100}, // V
- {0b1001, 0b1001, 0b1011, 0b1101}, // W
- {0b1001, 0b0100, 0b0100, 0b1001}, // X
- {0b1001, 0b0100, 0b0100, 0b0100}, // Y
- {0b1111, 0b0001, 0b0010, 0b1111}, // Z
- {0b1111, 0b1001, 0b1001, 0b0000}, // 0
- {0b0010, 0b1111, 0b0000, 0b0000}, // 1
- {0b1111, 0b0010, 0b1111, 0b0000}, // 2
- {0b1111, 0b0010, 0b1111, 0b0010}, // 3
- {0b1001, 0b1111, 0b0001, 0b0001}, // 4
- {0b1111, 0b1000, 0b1111, 0b0010}, // 5
- {0b1111, 0b1000, 0b1111, 0b1001}, // 6
- {0b1111, 0b0001, 0b0001, 0b0001}, // 7
- {0b1111, 0b1001, 0b1111, 0b1001}, // 8
- {0b1111, 0b1001, 0b1111, 0b0010}, // 9
- {0b0000, 0b0000, 0b0000, 0b0000} // Space
- };
- // Zig-zag mapping function
- int XY(int x, int y) {
- // Zig-zag mapping; even rows left-to-right, odd rows right-to-left
- return (y % 2 == 0) ? (y \* WIDTH + x) : (y \* WIDTH + (WIDTH - 1 - x));
- }
- // Draw a single column of a character
- void drawColumn(uint8\_t charIndex, int col, int xOffset, CRGB color) {
- for (int y = 0; y < HEIGHT; y++) {
- int x = xOffset + col; // Offset the column
- if (font\[charIndex\]\[col\] & (1 << y)) { // Check the font bitmap
- int index = XY(x, y); // Get the correct LED index
- if (index >= 0 && index < NUM\_LEDS) { // Bounds check
- leds\[index\] = color;
- }
- }
- }
- }
- // Draw a character
- void drawChar(char c, int xOffset, CRGB color) {
- int charIndex = (c >= 'A' && c <= 'Z') ? c - 'A' : (c >= '0' && c <= '9') ? c - '0' + 26 : 36; // 36 for space
- for (int col = 0; col < 4; col++) {
- drawColumn(charIndex, col, xOffset, color);
- }
- }
- // Scroll text across the grid
- void scrollText(const char\* text, CRGB color) {
- static int scrollOffset = WIDTH; // Start from the right edge
- static unsigned long lastUpdate = 0;
- if (millis() - lastUpdate > scrollSpeed) {
- lastUpdate = millis();
- // Clear the grid
- fill\_solid(leds, NUM\_LEDS, CRGB::Black);
- // Draw the scrolling text
- int textLength = strlen(text);
- for (int i = 0; i < textLength; i++) {
- drawChar(text\[i\], (i \* 5) - scrollOffset, color);
- }
- scrollOffset++;
- if (scrollOffset > (textLength \* 5) + WIDTH) { // Reset appropriately
- scrollOffset = 0; // Reset back to the start
- }
- FastLED.show();
- }
- }
- void setup() {
- FastLED.addLeds<WS2812, LED\_PIN, COLOR\_ORDER>(leds, NUM\_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- scrollText(text, CRGB::Red); // Scroll text in red
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement