#include <FastLED.h>
#define LED_PIN 2
#define COLOR_ORDER GRB
#define CHIPSET WS2811
#define BRIGHTNESS 255
#define UPDATES_PER_SECOND 100
// Params for width and height
const uint8_t kMatrixWidth = 5;
const uint8_t kMatrixHeight = 5;
// Param for different pixel layouts
const bool kMatrixSerpentineLayout = true;
const bool kMatrixVertical = false;
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
if (kMatrixVertical == false) {
i = (y * kMatrixWidth) + x;
} else {
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
}
}
if( kMatrixSerpentineLayout == true) {
if (kMatrixVertical == false) {
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;
}
} else { // vertical positioning
if ( x & 0x01) {
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
} else {
i = kMatrixHeight * (kMatrixWidth - x) - (y+1);
}
}
}
return i;
}
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
CRGB leds_plus_safety_pixel[ NUM_LEDS + 1];
CRGB* const leds( leds_plus_safety_pixel + 1);
void setup() {
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
}
void loop()
{
for (int i = 0; i < 360; i++) {
for (uint8_t y = 0; y < kMatrixHeight; y++){
for (uint8_t x = 0; x < kMatrixWidth; x++){
float angle = radians(i + (x * 360 / (kMatrixWidth - 1) / 2));
float phaseY = y * 128 / (kMatrixHeight - 1);
int brightness = (192) + (63) * sin(angle) - (phaseY);
leds[XY(x, y)] = CRGB::White / 255 * brightness;
}
}
FastLED.delay(1000 / UPDATES_PER_SECOND);
FastLED.show();
}
}