#include <FastLED.h>
#define LED_PIN 3
#define COLOR_ORDER GRB
#define CHIPSET WS2811
#define BRIGHTNESS 254
const uint8_t kMatrixWidth = 10;
const uint8_t kMatrixHeight = 10;
uint8_t hue;
const bool kMatrixSerpentineLayout = true;
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
}
if( kMatrixSerpentineLayout == true) {
if( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
return i;
}
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
CRGB leds_plus_safety_pixel[ NUM_LEDS + 1];
CRGB* const leds( leds_plus_safety_pixel + 1);
uint16_t XYsafe( uint8_t x, uint8_t y)
{
if( x >= kMatrixWidth) return -1;
if( y >= kMatrixHeight) return -1;
return XY(x,y);
}
void loop()
{
spiral(0,5,10);
//spiral(5,5,10);
spiral(10,5,50);
fadeToBlackBy(leds, NUM_LEDS, 1);
}
void setup() {
Serial.begin(115200);
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness( BRIGHTNESS );
}
void spiral(int offSet, int radMax, int speed){
int radius = beatsin8(speed, 0, radMax);;
int cX = kMatrixWidth/2;
int cY = kMatrixHeight/2;
int thisX = cX+(floor(radius*sin(millis()*.03+offSet)));
int thisY = cY+(floor(radius*cos(millis()*.03+offSet)));
leds[XY(thisX,thisY)] = CHSV( hue++, 255, 255);
//fadeToBlackBy(leds, NUM_LEDS, 5);
FastLED.show();
}