-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunicorn-attiny85.ino
265 lines (142 loc) · 5.67 KB
/
unicorn-attiny85.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include <FastLED.h>
#include <autoDelay.h>
#define LED_PIN 0
#define NUM_LEDS 16
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGBArray <NUM_LEDS> leds;
#define UPDATES_PER_SECOND 30
#define HUE_STEPS 5 // Number of steps to advance through palette between each for loop. Origionally 3
uint8_t updates_per_second = 30;
// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
//
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
//
// USING palettes is MUCH simpler in practice than in theory, so first just
// run this sketch, and watch the pretty lights as you then read through
// the code. Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
//
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
//
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.
#include "colour_palettes.h"
#include "pride_palettes.h"
#include "globals.h"
//extern CRGBPalette16 myRedWhiteBluePalette;
//extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
// set up instance of palette
//CRGBPalette16 tropicalPalette;
uint32_t transition_timer = 45; // effect transitions are in seconds
#define RANDOMISE_DIRECTION true
#define START_PALETTE RainbowColors_p // Sterile while palette to start with
//#define START_PALETTE select_palette(random(0, NUM_FX));
#define FADE_THROUGH_DELAY 1 // delay time between brightness changes during crossfade through black effect (millis)
#define PAUSE_BLACK_DELAY 1 // delay time to pause at black between crossfade for cleaner scene change effect
#include "colour_functions.h"
bool transitionActive = false;
bool animationTriggered = false;
uint32_t animationEndTime;
//uint32_t animation_delay = 33; // 33mS delay = 30 frames per second
#define BUTTON_ADC_PIN A1
#include "tinyButton.h"
tinyButton buttons(BUTTON_ADC_PIN);
void setup() {
buttons.begin();
fastled_setup();
currentPalette = START_PALETTE;
// currentPalette = select_palette(random(0, 5));
currentBlending = LINEARBLEND;
// nextPalette = select_palette(random(0, NUM_FX));
nextPalette = START_PALETTE;
}
uint8_t animationMode = 0; // When 0 animation mode is "stock" running through pallets as normal 1 - 4 will trigger various emote animations
void loop() {
int buttonState = buttons.tinyButtonLoop();
animationMode = buttonState;
if (animationMode == 0) {
// Normal Operation Cycles through Pride Colours
if (transitionActive or animationTriggered) {
exitAnimation();// Picks a new pallet to exit from an animation
exitTransition();
} else {
normalMode();
}
} else if (animationMode == 1) {
angryMode();
} else if (animationMode == 2) {
rainbowFart();
} else if (animationMode == 3) {
powerUp();
} else if (animationMode == 4) {
cantChoose();
}
if (RANDOMISE_DIRECTION ) {
randomise_led_directions(); // Changes the direction the LEDs are painted in
// randomise_colour_direction(); // < Dont like the effect this has meant to randomise the direction of the colour wheel, but causes jumps and skips
}
apply_fadethrough();
apply_palette(); //applies palette to LED buffer
FastLED.show();
FastLED.delay(1000 / updates_per_second);
}
#define NORMAL_BLEND_SPEED 12
void normalMode() {
updates_per_second = 30;
nblendPaletteTowardPalette(currentPalette, nextPalette, NORMAL_BLEND_SPEED); // slow blend between palettes
switchPalette(); // Switches colour palette periodically (actually only changes nextPalette, which is blended into currentPalette u
}
#define ANIMATION_BLEND_SPEED 128
void angryMode() {
updates_per_second = 150;
animationTriggered = true;
nextPalette = angry_red;
nblendPaletteTowardPalette(currentPalette, nextPalette, ANIMATION_BLEND_SPEED); // slow blend between palettes
}
void rainbowFart() {
updates_per_second = 500;
animationTriggered = true;
nextPalette = RainbowColors_p;
nblendPaletteTowardPalette(currentPalette, nextPalette, ANIMATION_BLEND_SPEED); // slow blend between palettes
}
void powerUp() {
updates_per_second = 300;
animationTriggered = true;
ledDirection = false;
// currentPalette = hotpink_blue;
nextPalette = enby;
//nextPalette = lesbian;
nblendPaletteTowardPalette(currentPalette, nextPalette, ANIMATION_BLEND_SPEED); // slow blend between palettes
}
void cantChoose() {
updates_per_second = 500;
animationTriggered = true;
// currentPalette = hotpink_blue;
nextPalette = hotpink_blue;
nblendPaletteTowardPalette(currentPalette, nextPalette, ANIMATION_BLEND_SPEED); // slow blend between palettes
}
void exitAnimation() { // Called once when animation ends
if (animationTriggered) {
// fadetoblack = true;
currentPalette = nextPalette;
nextPalette = select_palette(random(0, NUM_FX));
animationTriggered = false;
transitionActive = true;
animationEndTime = millis();
}
}
#define TRANSITION_TIME 1000
void exitTransition() { // Stays true untill pallette has been switched back to normal
if (transitionActive) {
// fadetoblack = true;
nblendPaletteTowardPalette(currentPalette, nextPalette, ANIMATION_BLEND_SPEED); // slow blend between palettes
if (millis() - animationEndTime >= TRANSITION_TIME) {
transitionActive = false;
}
}
}