#include <FastLED.h>
#define LED_PIN 23
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define MAX_EFFECT 27
const uint8_t kSquareWidth = 16;
const uint8_t HEIGHT = 16;
const uint8_t WIDTH = 16;
const uint8_t kBorderWidth = 1U;
static const byte maxDim = max(WIDTH, HEIGHT);
byte effectScaleParam[MAX_EFFECT]; // Динамический параметр эффекта
#define NUM_LEDS (kSquareWidth*kSquareWidth)
CRGB leds[NUM_LEDS];
void setup()
{
FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
Serial.begin(115200);
delay(10);
Serial.println("BLA");
}
void loop()
{
// Apply some blurring to whatever's already on the matrix
// Note that we never actually clear the matrix, we just constantly
// blur it repeatedly. Since the blurring is 'lossy', there's
// an automatic trend toward black -- by design.
uint8_t blurAmount = dim8_raw( beatsin8(3,64,100) );
blur2d( leds, kSquareWidth, kSquareWidth, blurAmount);
// Use two out-of-sync sine waves
uint8_t i = beatsin8( 91, kBorderWidth, maxDim-kBorderWidth);
uint8_t j = beatsin8( 109, kBorderWidth, maxDim-kBorderWidth);
uint8_t k = beatsin8( 73, kBorderWidth, maxDim-kBorderWidth);
uint8_t m = beatsin8( 123, kBorderWidth, maxDim-kBorderWidth);
// The color of each point shifts over time, each at a different speed.
uint32_t ms = millis();
int16_t idx, wh = WIDTH * HEIGHT;
// 27(4)
// 28(5..1...2)
// 29(5.4..3...2....1.....5.4)
// 30(5)
// 31(5)
// 32(5.4...........5.4...........5.4.........)
// 33(5)
// 34(5)
// 40(1)
// 41(4)
// 42(1)
// 43(4)
// 63(5)
// 64(4)
// 65(5)
// 66(5)
// 72(5.4)
// 73(5)
// 74(fast random)
// 75(более упорядоченный fast random)
// 76(5)
// 95(5)
// 96(4)
// 97(5)
// 98(5)
// 99(5)
// 100(5)
byte cnt = map(255-effectScaleParam[29],0,255,1,5);
Serial.println(cnt);
if (cnt <= 1) { idx = XY(i, j); if (idx < wh) leds[idx] += CHSV( ms / 29, 200U, 255U); }
if (cnt <= 2) { idx = XY(j, k); if (idx < wh) leds[idx] += CHSV( ms / 41, 200U, 255U); }
if (cnt <= 3) { idx = XY(k, m); if (idx < wh) leds[idx] += CHSV( ms / 73, 200U, 255U); }
if (cnt <= 4) { idx = XY(m, i); if (idx < wh) leds[idx] += CHSV( ms / 97, 200U, 255U); }
FastLED.show();
}
// Trivial XY function for the 8x8 grid; use a different XY
// function for different matrix grids. See XYMatrix example for code.
// uint16_t XY( uint8_t x, uint8_t y) { return (y * kSquareWidth) + x; }
uint16_t XY(uint8_t x, uint8_t y)
{
uint16_t i;
uint8_t reverse;
if (WIDTH >= HEIGHT) {
if (y & 0x01)
{
// Odd rows run backwards
reverse = (WIDTH - 1) - x;
i = (y * WIDTH) + reverse;
}
else
{
// Even rows run forwards
i = (y * WIDTH) + x;
}
} else {
if (x & 0x01)
{
// Odd rows run backwards
reverse = (HEIGHT - 1) - y;
i = (x * HEIGHT) + reverse;
}
else
{
// Even rows run forwards
i = (x * HEIGHT) + y;
}
}
return i;
}