#include <FastLED.h>
#define pWIDTH 16
#define pHEIGHT 28
#define NUM_LEDS ((pWIDTH) * (pHEIGHT))
extern CRGBPalette16 gCurrentGradientPalette;
extern CRGBPalette16 gTargetGradientPalette;
CRGB leds[NUM_LEDS];
bool loadingFlag = true;
void drawPixelXY(int8_t x, int8_t y, CRGB color) {
if (leds == nullptr) return;
if (x < 0 || x > pWIDTH - 1 || y < 0 || y > pHEIGHT - 1) return;
int16_t thisPixel = getPixelNumber(x, y);
if (thisPixel >= 0 && thisPixel < NUM_LEDS) leds[thisPixel] = color;
}
uint16_t getPixelNumber(uint8_t x, uint8_t y) {
if (x >= pWIDTH || y >= pHEIGHT)
return NUM_LEDS;
if (y & 1)
x = pWIDTH - 1 - x;
return x + (y * pWIDTH);
}
uint32_t getPixColor(int16_t thisPixel) {
if (leds == nullptr) return 0;
if (thisPixel < 0 || thisPixel > NUM_LEDS - 1) return 0;
return (((uint32_t)leds[thisPixel].r << 16) | ((uint32_t)leds[thisPixel].g << 8 ) | (uint32_t)leds[thisPixel].b);
}
uint32_t getPixColorXY(int8_t x, int8_t y) {
return getPixColor(getPixelNumber(x, y));
}
uint16_t XY(uint8_t x, uint8_t y) {
return getPixelNumber(x, y);
}
void shiftWave() {
for (uint8_t x = 0; x < pWIDTH; x++) {
for (uint8_t y = 0; y < pHEIGHT; y++) {
drawPixelXY(x, pHEIGHT -y, getPixColorXY(x, pHEIGHT-y - 1));
//int16_t idx = getPixelNumber(x, y + 1);
//if (idx >= 0 && idx < NUM_LEDS) leds[idx].nscale8_video(200); //map8(getEffectScaleParamValue2(thisMode),0,235)
}
}
}
void setup() {
FastLED.addLeds<WS2812B, 3, GRB>(leds, NUM_LEDS);
}
void loop() {
if (loadingFlag) {
loadingFlag = false;
FastLED.clear();
}
static uint8_t hue=0;
static int16_t sat=255;
static int16_t bri=255;
static uint8_t pos;
EVERY_N_SECONDS(15) {chooseNextPalette();}
EVERY_N_MILLISECONDS(12) nblendPaletteTowardPalette( gCurrentGradientPalette, gTargetGradientPalette, 12);
shiftWave();
for (uint8_t x = pWIDTH-1; x > 0; x--){
drawPixelXY(x, 0, getPixColorXY(x - 1, 0));
}
if(++pos >= pWIDTH) pos = 0;
if(pos < pWIDTH/2) hue = 0; else hue = 92;
// if(pos <= pWIDTH/2) {
// sat += 256/(pWIDTH/2);
// if(sat>255) sat = 255;
// } else {
// sat -= 256/(pWIDTH/2);
// if(sat<0) sat = 0;
// }
if(pos <= pWIDTH/2) {
bri += 256/(pWIDTH);
if(bri>255) bri = 255;
} else {
bri -= 256/(pWIDTH);
if(bri<0) bri = 0;
}
drawPixelXY(0, 0, CHSV(hue, sat, bri));
FastLED.delay(100);
}