//source: https://editor.soulmatelights.com/gallery/255-twist
#include "FastLED.h"
#define DATA_PIN 2
#define BRIGHTNESS 255
#define NUM_LEDS 256
#define NUM_COLS 16
#define NUM_ROWS 16
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
//#define FRAMES_PER_SECOND 60
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
const bool kMatrixSerpentineLayout = false;
byte hue = 0;
void patt1(uint8_t i, uint8_t j, uint8_t color1, uint8_t color2) {
// leds[XY(i, j)] = CHSV(0, 255, 0);
leds[XY(i + 1, j)] = CHSV(color1, 255, BRIGHTNESS);
leds[XY(i + 1, j + 1)] = CHSV(color1, 255, BRIGHTNESS);
leds[XY(i, j + 1)] = CHSV(color2, 255, BRIGHTNESS);
}
void patt2(uint8_t i, uint8_t j, uint8_t color1, uint8_t color2) {
// leds[XY(i, j)] = CHSV(0, 255, 0);
leds[XY(i + 1, j)] = CHSV(color1, 255, BRIGHTNESS);
leds[XY(i + 1, j + 1)] = CHSV(color2, 255, BRIGHTNESS);
leds[XY(i, j + 1)] = CHSV(color2, 255, BRIGHTNESS);
}
void setup() {
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);
FastLED.setBrightness(BRIGHTNESS);
//Serial.begin(115200);
}
void loop()
{
EVERY_N_MILLISECONDS(50) { hue++; }
for (byte i = 0; i < NUM_COLS; i += 4) {
for (byte j = 0; j < NUM_ROWS; j += 4) {
patt1(i, j, 64 + j + hue, i + hue);
patt1(i + 2, j + 2, 64 + j + hue, i + hue);
patt2(i, j + 2, 64 + j + hue, i + hue);
patt2(i + 2, j, 64 + j + hue, i + hue);
}
}
FastLED.show();
}
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;
}