-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonoffshifter.cpp
39 lines (36 loc) · 1.03 KB
/
onoffshifter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//*****************************************************************************
// 20 on 20 off shifting
//*****************************************************************************
#include "FastLED.h"
#include "common.h"
#include "onoffshifter.h"
#include "DebugMacros.h"
void onoffshifter()
{
DPRINTLN_L("onoffshifter:");
onoffinit();
shift(20);
fill_solid(&(leds[0]), NUM_LEDS, CRGB(0, 0, 0)); //all off
FastLED.show();
}
void shift(int wait) {
for (int iLed = 0; iLed < NUM_LEDS; iLed++) {
delay(wait);
CRGB tmp = leds[NUM_LEDS - 1];
memmove(&leds[1], &leds[0], (NUM_LEDS - 1)*sizeof(CRGB));
leds[0] = tmp;
FastLED.show();
}
}
void onoffinit() {
// generate initial pattern
// 1. Fill all positions
fill_solid(&(leds[0]), NUM_LEDS, CRGB(random(255), random(255), random(255)));
// 2. Switch off every 20 leds
for (byte i = 0; i < NUM_LEDS;)
{
for (byte j = 0; j < BLOCKSIZE; j++)
leds[j + BLOCKSIZE + i] = CRGB(0, 0, 0);
i += (2 * BLOCKSIZE);
}
}