forked from timpear/NeoCandle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeoCandle16
More file actions
126 lines (111 loc) · 2.79 KB
/
NeoCandle16
File metadata and controls
126 lines (111 loc) · 2.79 KB
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
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, 0, NEO_GRB + NEO_KHZ800);
const int x = 16;
int redPx = 255;
int grnHigh = 135; //110-120 for 5v, 135 for 3.3v
int bluePx = 15; //10 for 5v, 15 for 3.3v
// animation time variables, with recommendations
int burnDepth = 14; //10 for 5v, 14 for 3.3v -- how much green dips below grnHigh for normal burn -
int flutterDepth = 30; //25 for 5v, 30 for 3.3v -- maximum dip for flutter
int cycleTime = 120; //120 -- duration of one dip in milliseconds
// pay no attention to that man behind the curtain
int fDelay;
int fRep; // function duration input, multiplied by 1000 to be used with delay()
int flickerDepth;
int burnDelay;
int burnLow;
int flickDelay;
int flickLow;
int flutDelay;
int flutLow;
void setup() {
flickerDepth = (burnDepth + flutterDepth) / 2.4;
burnLow = grnHigh - burnDepth;
burnDelay = (cycleTime / 2) / burnDepth;
flickLow = grnHigh - flickerDepth;
flickDelay = (cycleTime / 2) / flickerDepth;
flutLow = grnHigh - flutterDepth;
flutDelay = ((cycleTime / 2) / flutterDepth);
strip.setBrightness(70);
strip.begin();
strip.show();
}
// In loop, call CANDLE STATES, with duration in seconds
// 1. on() = solid yellow
// 2. burn() = candle is burning normally, flickering slightly
// 3. flicker() = candle flickers noticably
// 4. flutter() = the candle needs air!
void loop() {
burn(10);
flicker(5);
burn(8);
flutter(2);
burn(3);
on(10);
burn(10);
flicker(10);
}
// basic fire funciton - not called in main loop
void fire(int grnLow) {
for (int grnPx = grnHigh; grnPx > grnLow; grnPx--) {
for (int j = 0; j < x; j++){
strip.setPixelColor(j, redPx, grnPx, bluePx);
}
strip.show();
delay(fDelay);
}
for (int grnPx = grnLow; grnPx < grnHigh; grnPx++) {
for (int j = 0; j < x; j++){
strip.setPixelColor(j, redPx, grnPx, bluePx);
}
strip.show();
delay(fDelay);
}
}
// fire animation
void on(int f) {
fRep = f * 1000;
int grnPx = grnHigh - 5;
for (int j = 0; j < x; j++){
strip.setPixelColor(j, redPx, grnPx, bluePx);
}
strip.show();
delay(fRep);
}
void burn(int f) {
fRep = f * 8;
fDelay = burnDelay;
for (int var = 0; var < fRep; var++) {
fire(burnLow);
}
}
void flicker(int f) {
fRep = f * 8;
fDelay = burnDelay;
fire(burnLow);
fDelay = flickDelay;
for (int var = 0; var < fRep; var++) {
fire(flickLow);
}
fDelay = burnDelay;
fire(burnLow);
fire(burnLow);
fire(burnLow);
}
void flutter(int f) {
fRep = f * 8;
fDelay = burnDelay;
fire(burnLow);
fDelay = flickDelay;
fire(flickLow);
fDelay = flutDelay;
for (int var = 0; var < fRep; var++) {
fire(flutLow);
}
fDelay = flickDelay;
fire(flickLow);
fire(flickLow);
fDelay = burnDelay;
fire(burnLow);
fire(burnLow);
}