-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode_fill.cpp
102 lines (89 loc) · 2.13 KB
/
mode_fill.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <Arduino.h>
#include <rgb_lcd.h>
#include <FastLED.h>
#include "settings.h"
#include "utils.h"
#include "mode_fixed.h"
extern CRGB leds[NUM_LEDS];
void mode_fill(boolean firstRun) {
int density = 10 - getModeSetting(MODE_FILL, 0);
int speed = 2 * (10 - getModeSetting(MODE_FILL, 1));
static long lastUpdate = millis();
static int dir = 1;
int ribbons[][2] = {
{ 0, 15 }, // upper right leg inside
{ 16, 35 }, // upper right leg outside
{ 36, 50 }, // lower right leg outside
{ 51, 65 }, // lower right leg inside
{ 66, 81 }, // upper left leg inside
{ 82, 101 } // upper left leg outside
};
int ribbon[] = { 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, };
const int length = 31;
static int led[length];
static int top = 0;
static int bottom = 0;
if (firstRun) {
memset(&led[0], 0, sizeof(led));
top = 0;
}
static long lastLed = millis();
int delay = 1;
int timeGap = density * 100 * delay;
if (millis() - lastUpdate > delay) {
lastUpdate = millis();
if (dir == 1) { // filling up
for (int i = top; i < length; i++) {
if (led[i] > 0) {
led[i]--;
if (led[i] == 0) {
if (i - 1 <= top) {
led[top] = 1;
top++;
}
else {
led[i - 1] = max(1, (1 - ((float)(i - top) / (float)(length - top))) * speed);
}
}
}
}
if (top == length) {
top = 0;
dir = -1;
memset(&led[0], 1, sizeof(led));
}
} else { // emptying
p("emptying\n");
for (int i = 0; i < bottom; i++) {
if (led[i] > 0) {
led[i]--;
if (led[i] == 0 && i > 0) {
led[i - 1] = max(1, (1 - ((float)(bottom - i) / (float)(bottom))) * speed);
}
}
}
}
if (millis() - lastLed > timeGap) {
lastLed = millis();
if (dir == 1) {
led[length - 1] = 1;
} else {
bottom++;
if (bottom == length) {
dir = 1;
}
}
// p("new led\n");
}
p("\n");
memset(&leds[0], 0, sizeof(leds));
for (int i = 0; i < length; i++) {
if (led[i] > 0) {
leds[ribbon[i]] = CHSV(0, 0, 255);
}
p("%u ", led[i]);
}
p("\n");
LEDS.show();
}
}