#include <FastLED.h>
#define LED_PIN 3
#define COLOR_ORDER GRB
#define CHIPSET WS2811
#define BRIGHTNESS 255
#define kMatrixWidth 22
#define kMatrixHeight 9
#define NUM_LEDS 300
CRGB leds_plus_safety_pixel[ NUM_LEDS + 1];
CRGB* const leds( leds_plus_safety_pixel + 1);
struct XmasRows {
uint16_t start;
uint8_t length;
};
XmasRows xmasrows[] = {{293, 7}, {277, 8}, {255, 11}, {232, 12},
{201, 17}, {166, 16}, {119, 18}, {59, 22}, {4, 19}};
int16_t XY( uint8_t x, uint8_t y)
{
if (y >= kMatrixHeight) return -1;
// centre each row
int8_t rowxstart = (kMatrixWidth - xmasrows[y].length) / 2;
// offset by the centreing amount for this row
int16_t this_x = x - rowxstart;
if (this_x < 0 || this_x >= xmasrows[y].length) {
return -1;
}
return xmasrows[y].start + this_x;
}
// Demo that USES "XY" follows code below
void loop()
{
uint32_t ms = millis() / 30;
int32_t yHueDelta32 = ((int32_t)cos16( ms * (27/1) ) * (350 / kMatrixWidth)) / 2;
int32_t xHueDelta32 = ((int32_t)cos16( ms * (39/1) ) * (310 / kMatrixHeight)) / 2 ;
DrawOneFrame( ms / 65536, yHueDelta32 / 32768, xHueDelta32 / 32768);
FastLED.show();
}
void DrawOneFrame( byte startHue8, int8_t yHueDelta8, int8_t xHueDelta8)
{
byte lineStartHue = startHue8;
for( byte y = 0; y < kMatrixHeight; y++) {
lineStartHue += yHueDelta8;
byte pixelHue = lineStartHue;
for( byte x = 0; x < kMatrixWidth; x++) {
pixelHue += xHueDelta8;
leds[ XY(x, y)] = CHSV( pixelHue, 255, 255);
}
}
}
void setup() {
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness( BRIGHTNESS );
}