forked from gcorazza/Staff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStaff.ino
executable file
·156 lines (122 loc) · 3.75 KB
/
Staff.ino
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "FastLED.h"
#include "globals.h"
#include "lib.h"
#define DATA_PIN 6
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
Serial.begin(9600);
randomSeed(28);
delay(1000);
}
void loop() {
// slowLeftRight();
// lightningStrike();
setBulk(leds, 100, 120, CRGB(150,150,150));
// overlapping();
// fast();
// fireWater();
// FastLED.show();
}
float sin01(float x) {
return ((sin(x)) / (2.8)) + 0.5;
}
void slowLeftRight() {
long start = millis();
long now = millis();
int durationMs = 4000;
while (now - start < durationMs) {
double framePercent = ((double)(now - start)) / durationMs;
CRGB ledsg[NUM_LEDS];
clearLEDsInvisible(leds);
lightningFrame(leds, 0, 120, 40, 40, CRGB::Red, abs(framePercent * 2 - 1)*0.8);
FastLED.show();
now = millis();
}
FastLED.show();
}
void overlapping() {
float e = 2.71828182;
long start = millis();
long now = millis();
int durationMs = 20000;
while (now - start < durationMs) {
double framePercent = ((double)(now - start)) / durationMs;
CRGB ledsg[NUM_LEDS];
CRGB ledsb[NUM_LEDS];
clearLEDsInvisible(leds);
clearLEDsInvisible(ledsg);
clearLEDsInvisible(ledsb);
lightningFrame(leds, 0, 120, 40, 40, CRGB::Red, sin01(framePercent * 10));
lightningFrame(ledsg, 0, 120, 40, 40, CRGB::Green, sin01((framePercent + 4) * 8));
lightningFrame(ledsb, 0, 120, 20, 20, CRGB::Blue, sin01((framePercent + 6) * 12));
addToFirst(leds, ledsg);
addToFirst(leds, ledsb);
FastLED.show();
now = millis();
}
// clearLEDsInvisible(leds);
FastLED.show();
}
void fast() {
int widthFront = 10;
int widthBack = 10;
int durationMs = 2000;
float e = 2.71828182;
long start = millis();
long now = millis();
while (now - start < durationMs) {
double framePercent = ((double)(now - start)) / durationMs;
clearLEDsInvisible(leds);
lightningFrame(leds, 120, 0, widthFront, widthBack, CRGB::White, ((sin(pow(e, (framePercent * 3.3 + 0.5)))) / (2.5)) + 0.5);
FastLED.show();
now = millis();
}
clearLEDsInvisible(leds);
FastLED.show();
}
void fireWater() {
int widthFront = 10;
int widthBack = 10;
int durationMs = 10000;
long start = millis();
long now = millis();
while (now - start < durationMs) {
double framePercent = ((double)(now - start)) / durationMs;
clearLEDsInvisible(leds);
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
CRGB leds4[NUM_LEDS];
lightningFrame(leds, 0, 62, widthFront, widthBack, CRGB::Red, framePercent);
lightningFrame(leds2, 120, 58, widthFront, widthBack, CRGB::Blue, framePercent);
addToFirst(leds, leds2);
FastLED.show();
now = millis();
}
clearLEDsInvisible(leds);
FastLED.show();
}
void lightningStrike() {
int widthFront = 2;
int widthBack = 10;
int durationMs = 1000;
long start = millis();
long now = millis();
float modifier[20] = { 0, 0.4169913895607595, 0.5618039271819768, 0.6578185439802253, 0.7283221409124393, 0.7826476292961627, 0.825613063541047, 0.860049404366313, 0.8878708941948211, 0.910247022889621, 0.927364489471808, 0.9410178852180805, 0.9524824099642146, 0.9622535793171002, 0.9706587718820873, 0.9779081236478762, 0.9841452330383459, 0.9894613822283056, 0.9938974691287625, 0.9974456444941892 };
while (now - start < durationMs) {
double framePercent = ((double)(now - start)) / durationMs;
clearLEDsInvisible(leds);
lightningFrame(leds, 0, 100, widthFront, widthBack, CRGB::Aqua, frameModifier(modifier, 20, framePercent) * 0.9);
FastLED.show();
now = millis();
}
clearLEDsInvisible(leds);
FastLED.show();
}
void ether() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(200, 0, 200) % random(0, 100);
}
FastLED.show();
delay(100);
}