#include "FastLED.h"
#define DATA_PIN 2
#define BRIGHTNESS 255
#define NUM_LEDS 256
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
// Define the array of leds
CRGB leds[NUM_LEDS];
uint8_t LED_COLS = 16;
uint8_t LED_ROWS = 16;
const bool kMatrixSerpentineLayout = true;
int offset = 0;
void setup() {
// put your setup code here, to run once:
delay(1000);
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS); //setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
offset = offset+2;
//offset = beatsin8(35, 0, 255);
for (int x = 0; x < LED_COLS; x++) {
for (int y = 0; y < LED_ROWS; y++) {
// XY tells us the index of a given X/Y coordinate
int index = XY(x, y);
// Let's take the X and Y values, and add them together to get the hue
int hue = x * 10 + y * 10;
// add the offset so it changes every frame
hue += offset;
leds[index] = CHSV(hue, 255, 255);
}
}
FastLED.show();
}
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
i = (y * LED_COLS) + x;
}
if( kMatrixSerpentineLayout == true) {
if( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (LED_COLS - 1) - x;
i = (y * LED_COLS) + reverseX;
} else {
// Even rows run forwards
i = (y * LED_COLS) + x;
}
}
return i;
}