#include <FastLED.h>
#define DATA_PIN 2
#define NUM_LEDS 256
#define BRIGHTNESS 255
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
const bool kMatrixSerpentineLayout = false;
const uint8_t kBorderWidth = 1;
uint8_t index = 0;
uint8_t freq_data[] = {
40, 40, 0,
40, 40, 64,
30, 60, 0,
30, 60, 32,
20, 60, 64,
40, 60, 0,
40, 60, 32,
40, 60, 64,
20, 80, 16,
20, 80, 0,
45, 60, 0,
45, 60, 64,
36, 60, 0,
40, 50, 0,
50, 60, 0
};
void setup() {
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);
//Serial.begin(115200);
// Serial.println("Hello, I'm in a terminal!");
}
void loop() {
EVERY_N_SECONDS(10) { // switch pattern every 10 second
index++;
if (index == 15) index = 0;
// Serial.println(index);
}
uint8_t blurAmount = beatsin8(5,10,220);
blur2d( leds, kMatrixWidth, kMatrixHeight, blurAmount);
// Two sine waves of specific frequency and phase shift
uint8_t i = beatsin8(freq_data[index*3], kBorderWidth, kMatrixHeight-kBorderWidth-1, 0, freq_data[index*3+2]);
uint8_t j = beatsin8(freq_data[index*3+1], kBorderWidth, kMatrixWidth-kBorderWidth-1);
// Also calculate some reflections
uint8_t ni = (kMatrixWidth-1)-i;
uint8_t nj = (kMatrixWidth-1)-j;
// The color of each point shifts over time, each at a different speed.
uint16_t ms = millis();
leds[XY( i, j)] += CHSV( ms / 11, 255, 255);
leds[XY( j, i)] += CHSV( ms / 13, 255, 255);
leds[XY(ni,nj)] += CHSV( ms / 17, 255, 255);
leds[XY(nj,ni)] += CHSV( ms / 29, 255, 255);
leds[XY( i,nj)] += CHSV( ms / 37, 255, 255);
leds[XY(ni, j)] += CHSV( ms / 41, 255, 255);
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;
}