#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 64
#define BRIGHTNESS 40
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
uint8_t colorIndex = 0;
// ১. নতুন পদ্ধতিতে প্যালেট তৈরি (এটি এরর মুক্ত)
DEFINE_GRADIENT_PALETTE( rainbow_gp ) {
0, 255, 0, 0,
32, 255, 255, 0,
64, 0, 255, 0,
128, 0, 0, 255,
192, 255, 0, 255,
255, 255, 0, 0
};
CRGBPalette16 myRainbow = rainbow_gp;
// ২. ফন্ট ডাটা (A-Z)
const uint8_t PROGMEM font[28][8] = {
{0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x66}, {0x7C,0x66,0x66,0x7C,0x66,0x66,0x7C,0x00},
{0x3C,0x66,0x60,0x60,0x60,0x66,0x3C,0x00}, {0x78,0x6C,0x66,0x66,0x66,0x6C,0x78,0x00},
{0x7E,0x60,0x60,0x7C,0x60,0x60,0x7E,0x00}, {0x7E,0x60,0x60,0x7C,0x60,0x60,0x60,0x00},
{0x3C,0x66,0x60,0x6E,0x66,0x66,0x3C,0x00}, {0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00},
{0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00}, {0x1E,0x0C,0x0C,0x0C,0x0C,0xCC,0x78,0x00},
{0x66,0x6C,0x78,0x70,0x78,0x6C,0x66,0x00}, {0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00},
{0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x00}, {0x66,0x6E,0x7E,0x76,0x66,0x66,0x66,0x00},
{0x3C,0x66,0x66,0x66,0x66,0x66,0x3C,0x00}, {0x7C,0x66,0x66,0x7C,0x60,0x60,0x60,0x00},
{0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00}, {0x7C,0x66,0x66,0x7C,0x78,0x6C,0x66,0x00},
{0x3C,0x66,0x60,0x3C,0x06,0x66,0x3C,0x00}, {0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x00},
{0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x00}, {0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00},
{0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00}, {0x66,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00},
{0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00}, {0x7E,0x06,0x0C,0x18,0x30,0x60,0x7E,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00}
};
void drawPixel(int x, int y, CRGB color) {
if (x >= 0 && x < 8 && y >= 0 && y < 8) {
int index;
if (x % 2 == 0) index = (x * 8) + y;
else index = (x * 8) + (7 - y);
leds[index] = color;
}
}
int getFontIndex(char c) {
if (c >= 'a' && c <= 'z') c -= 32;
if (c >= 'A' && c <= 'Z') return c - 'A';
if (c == ' ') return 26;
if (c == '.') return 27;
return 26;
}
void scrollTextWithPalette(String text, CRGBPalette16 palette, int speed) {
int textLen = text.length();
for (int scrollPos = 0; scrollPos < (textLen * 8) + 8; scrollPos++) {
FastLED.clear();
colorIndex += 4;
for (int charIdx = 0; charIdx < textLen; charIdx++) {
int charXPos = (charIdx * 8) - scrollPos + 8;
if (charXPos > -8 && charXPos < 8) {
int fontIdx = getFontIndex(text[charIdx]);
for (int row = 0; row < 8; row++) {
uint8_t rowData = pgm_read_byte(&(font[fontIdx][row]));
for (int col = 0; col < 8; col++) {
if (rowData & (1 << (7 - col))) {
CRGB pixelColor = ColorFromPalette(palette, colorIndex + (charXPos * 5));
drawPixel(charXPos + col, row, pixelColor);
}
}
}
}
}
FastLED.show();
delay(speed);
}
}
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
scrollTextWithPalette("KALINGA CORPORATION", myRainbow, 80);
scrollTextWithPalette("KALINGA CORPORATION", myRainbow[2], 80);
}