вот например
Варианты управления гирляндой / лентой - Отвлечённые темы - Arduino.ru
Спойлер
void pattern_random(unsigned char * oneBuf, unsigned short tIn) {
if (tIn % 8) return;
for (unsigned short i = 0; i < count_bytes_in_buf; ++i) *(oneBuf+i) = random();
}
void pattern_snakes(unsigned char * oneBuf, unsigned short tIn) {
for (unsigned short i = 0; i < numLEDSws281X; ++i) {
unsigned short x = (i + (tIn >> 1)) % 64;
if (x < 10){
*(oneBuf+i*ws281x_bytes_per_pixel) = 0xFF; // R
} else if (x >= 15 && x < 25) {
*(oneBuf+i*ws281x_bytes_per_pixel+1) = 0xFF; // G
} else if (x >= 30 && x < 40) {
*(oneBuf+i*ws281x_bytes_per_pixel+2) = 0xFF; // B
} else {
*(oneBuf+i*ws281x_bytes_per_pixel) = 0x00; // R
*(oneBuf+i*ws281x_bytes_per_pixel+1) = 0x00; // G
*(oneBuf+i*ws281x_bytes_per_pixel+2) = 0x00; // B
}
if (ws281x_bytes_per_pixel>3) *(oneBuf+i*ws281x_bytes_per_pixel+3) = 0x00; // W
}
}
void pattern_sparkle(unsigned char * oneBuf, unsigned short tIn) {
if (tIn % 8) return;
for (unsigned short i = 0; i < numLEDSws281X; ++i) {
unsigned char putByte = random() % 16 ? 0 : 0xFF;
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+i*ws281x_bytes_per_pixel+j) = putByte;
}
}
void pattern_greys(unsigned char * oneBuf, unsigned short tIn) {
for (unsigned short i = 0; i < numLEDSws281X; ++i) {
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+i*ws281x_bytes_per_pixel+j) = (unsigned char)tIn;
}
}
void pattern_blink(unsigned char * oneBuf, unsigned short tIn) {
static unsigned char cR, cG, cB;
static unsigned short currPos = 0;
static unsigned short currPeriod;
if (!currPos) { // start new
cR = random(); cG = random(); cB = random();
for (unsigned short i = 0; i < numLEDSws281X; ++i) {
*(oneBuf+i*ws281x_bytes_per_pixel) = cR;
*(oneBuf+i*ws281x_bytes_per_pixel+1) = cG;
*(oneBuf+i*ws281x_bytes_per_pixel+2) = cB;
if (ws281x_bytes_per_pixel>3) *(oneBuf+i*ws281x_bytes_per_pixel+3) = cR+cG+cB;
}
++currPos;
currPeriod = 20 + (random() >> 2);
} else { // cont
if (currPos == 3) for (unsigned short i = 0; i < count_bytes_in_buf; ++i) *(oneBuf+i) = 0;
if ((++currPos) >= currPeriod) currPos = 0;
}
}
void pattern_fillr(unsigned char * oneBuf, unsigned short tIn) {
if (tIn % 4) return;
static unsigned short i = 0;
static unsigned char fillMode = 0;
switch (fillMode) {
case 0: {
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+i*ws281x_bytes_per_pixel+j) = random();
break;
}
case 1: {
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+i*ws281x_bytes_per_pixel+j) = 0;
break;
}
case 2: {
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+(numLEDSws281X-i-1)*ws281x_bytes_per_pixel+j) = random();
break;
}
case 3: {
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+(numLEDSws281X-i-1)*ws281x_bytes_per_pixel+j) = 0;
break;
}
default: {}
}
if ((++i) >= numLEDSws281X) {
i = 0;
if ((++fillMode) >= 4) fillMode = 0;
}
}
void pattern_bomb(unsigned char * oneBuf, unsigned short tIn) {
static unsigned short s = 16;
if (tIn % s) return;
static unsigned short i = 0;
static unsigned char fillMode = 0;
static unsigned char c1R, c2R, c1G, c2G, c1B, c2B;
if ((!i) && (!fillMode)) {
c1R = random(); c1G = random(); c1B = random();
c2R = random(); c2G = random(); c2B = random();
s = 16;
}
switch (fillMode) {
case 0: {
*(oneBuf+i*ws281x_bytes_per_pixel) = c1R;
*(oneBuf+i*ws281x_bytes_per_pixel+1) = c1G;
*(oneBuf+i*ws281x_bytes_per_pixel+2) = c1B;
*(oneBuf+(numLEDSws281X-i-1)*ws281x_bytes_per_pixel) = c2R;
*(oneBuf+(numLEDSws281X-i-1)*ws281x_bytes_per_pixel+1) = c2G;
*(oneBuf+(numLEDSws281X-i-1)*ws281x_bytes_per_pixel+2) = c2B;
if (ws281x_bytes_per_pixel>3) {
*(oneBuf+i*ws281x_bytes_per_pixel+3) = c1R+c1G+c1B;
*(oneBuf+(numLEDSws281X-i-1)*ws281x_bytes_per_pixel+3) = c2R+c2G+c2B;
}
if (i) { // clear prev pixel
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+(i-1)*ws281x_bytes_per_pixel+j) = 0;
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+(numLEDSws281X-i)*ws281x_bytes_per_pixel+j) = 0;
}
break;
}
case 1: { // full fill pixel
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+((numLEDSws281X >> 1)-1-i)*ws281x_bytes_per_pixel+j) = 0xFF;
for (unsigned char j = 0; j < ws281x_bytes_per_pixel; ++j) *(oneBuf+((numLEDSws281X >> 1)+i)*ws281x_bytes_per_pixel+j) = 0xFF;
break;
}
default: {}
}
if ((++i) >= (numLEDSws281X >> 1)) { // half strip
i = 0;
if ((++fillMode) >= 2) {
fillMode = 0;
for (unsigned short i = 0; i < count_bytes_in_buf; ++i) *(oneBuf+i) = 0;
} else {
s = 4;
}
}
}