-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathanim.h
126 lines (89 loc) · 3.02 KB
/
anim.h
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
#ifndef anim_h
#define anim_h
#include <Adafruit_NeoPixel.h>
#include "palette.h"
#define PIN 2 // WS2812 pin number
#define LEDS 99 // number of LEDs in the strip. Not sure why, but 100 leds don't work with software serial! Works with hardware serial though
#define BRIGHTNESS 256// brightness adjustment, up to 256
#define TRANSITION_MS 1000 // transition time between animations, ms
// brigthness animation amplitude shift. true BrA amplitude is calculated as (0..127) value shifted right by this amount
#define BRA_AMP_SHIFT 1
// brigthness animation amplitude offset
#define BRA_OFFSET (222-64)
//probability of spark when in idle plase
#define SPARK_PROB 3
class Anim {
private:
//Color arrays - two for making transition
static Color leds1[LEDS];
static Color leds2[LEDS];
//auxiliary colors array
static Color ledstmp[LEDS];
void animStart();
// length of animation timeslot (period)
byte period;
// array of Color to work with
Color *leds;
Palette *palette;
// millis for next timeslot
unsigned long nextms;
// millis to transition end
unsigned long transms;
int phase;
int pos;
int inc;
//whether to call SetUp on palette change
//(some animations require full transition with fade, otherwise the colors would change in a step, some not)
bool setUpOnPalChange;
Color curColor = Color(0);
Color prevColor = Color(0);
Color sparkleColor = Color(0xFFFFFF);
static byte seq[LEDS];
//brigthness animation (BrA) current initial phase
byte braPhase;
//braPhase change speed
byte braPhaseSpd=5;
//BrA frequency (spatial)
byte braFreq=150;
//glow animation setup
void glowSetUp();
//glow animation - must be called for each LED after it's BASIC color is set
//note this overwrites the LED color, so the glow assumes that color will be stored elsewhere (not in leds[])
//or computed each time regardless previous leds[] value
void glowForEachLed(int i);
//glow animation - must be called at the end of each animaton run
void glowRun();
void setUp();
//run and setup handlers
void (Anim::*runImpl)();
void (Anim::*setUpImpl)();
//animation implementations
void animStart_SetUp();
void animStart_Run();
void animRun_SetUp();
void animRun_Run();
void animPixieDust_SetUp();
void animPixieDust_Run();
void animSparkr_SetUp();
void animSparkr_Run();
void animRandCyc_SetUp();
void animRandCyc_Run();
void animStars_SetUp();
void animStars_Run();
void animSpread_SetUp();
void animSpread_Run();
void animFly_SetUp();
void animFly_Run();
void animBT_SetUp();
void animBT_Run();
public:
Anim();
void setPeriod(byte period);
void setPalette(Palette * pal);
void setAnim(byte animInd);
bool run();//returns true if actual change has completed, or false if it's dummy call (previous call was too recent in time)
void doSetUp();
};
unsigned int rng();
byte rngb();
#endif