-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweighted_shifter.cpp
50 lines (42 loc) · 1.46 KB
/
weighted_shifter.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
40
41
42
43
44
45
46
47
48
49
50
//*****************************************************************************
// block of weighted random colour shifting back and forth
//*****************************************************************************
#include "FastLED.h"
#include "common.h"
#include "weighted_shifter.h"
#include "DebugMacros.h"
void weighted_shifter()
{
DPRINTLN_L("weighted_shifter:");
fill_solid(&(leds[0]), NUM_LEDS, CRGB(0, 0, 0)); //all off
FastLED.show();
int hue = random(255);
int step_value = 255 / (BLOCK_SIZE / 2);
//fill_with pattern
for (int iLed = 0; iLed < BLOCK_SIZE / 2; iLed++)
leds[iLed] = CHSV(hue, 255, step_value * iLed);
for (int iLed = BLOCK_SIZE / 2; iLed < BLOCK_SIZE; iLed++)
leds[iLed] = CHSV(hue, 255, step_value * (BLOCK_SIZE - iLed));
FastLED.show();
shiftx2(10, BLOCK_SIZE);
reverseshiftx2(10, BLOCK_SIZE);
fill_solid(&(leds[0]), NUM_LEDS, CRGB(0, 0, 0)); //all off
FastLED.show();
}
void shiftx2(int wait, int blocksize) {
for (int iLed = 0; iLed < (NUM_LEDS - blocksize); iLed++) {
delay(wait);
memmove(&leds[1], &leds[0], (NUM_LEDS - 1)*sizeof(CRGB));
leds[0] = CRGB(0, 0, 0);
FastLED.show();
}
}
void reverseshiftx2(int wait, int blocksize) {
for (int iLed = 0; iLed < (NUM_LEDS - blocksize); iLed++) {
delay(wait);
CRGB tmp = leds[0];
memmove(&leds[0], &leds[1], (NUM_LEDS - 1)*sizeof(CRGB));
leds[NUM_LEDS - 1] = tmp;
FastLED.show();
}
}