#include <FastLED.h>
#define pWIDTH 16
#define pHEIGHT 8
#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 setup() {
FastLED.addLeds<WS2812B, 3, GRB>(leds, NUM_LEDS);
}
uint8_t chA=0;
uint8_t chB=0;
uint8_t chC=0;
uint8_t offsetA=0;
uint8_t offsetB=0;
uint8_t offsetC=0;
void loop() {
if (loadingFlag) {
loadingFlag = false;
FastLED.clear();
offsetA=random8(pWIDTH);
offsetB=random8(pWIDTH);
offsetC=random8(pWIDTH);
}
// EVERY_N_SECONDS(4) {
// offsetA=random8(pWIDTH);
// offsetB=random8(pWIDTH);
// offsetC=random8(pWIDTH);
// }
//FastLED.clear();
fadeToBlackBy(leds, NUM_LEDS, 92);
if (chA==0) offsetA=random8(pWIDTH/2);
if (chB==0) offsetB=random8(pWIDTH/2);
if (chC==0) offsetC=random8(pWIDTH/2);
chA=beatsin8(pWIDTH+offsetA,0,pWIDTH-1);
chB=beatsin8(pWIDTH+offsetB,0,pWIDTH-1);
chC=beatsin8(pWIDTH+offsetC,0,pWIDTH-1);
for(uint8_t y=0; y<pHEIGHT; y++){
drawPixelXY(chA,y,CHSV(0, 255, 255));
drawPixelXY(chB,y,CHSV(64, 255, 255));
drawPixelXY(chC,y,CHSV(96, 255, 255));
}
// for(uint8_t x=0; x<pWIDTH; x++){
// drawPixelXY(x,chB,CHSV(0, 255, 255));
// drawPixelXY(x,chC,CHSV(64, 255, 255));
// drawPixelXY(x,chA,CHSV(96, 255, 255));
// }
FastLED.delay(60);
}