-
Notifications
You must be signed in to change notification settings - Fork 0
/
SunSet.cpp
74 lines (69 loc) · 1.1 KB
/
SunSet.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
#include "Arduino.h"
#include "SunSet.h"
SunSet::SunSet(PixelWrapper* strip) {
_strip = strip;
_lastticktime = millis();
_phase = 0;
_r = 255;
_g = 255;
_b = 255;
_steptime=100;
}
void SunSet::tick(){
int currentTime = millis();
if (currentTime - _lastticktime < _steptime) {
return;
}
_lastticktime=currentTime;
this->step();
_strip->show();
}
void SunSet::step(){
switch(_phase){
case 0:
_b--;
if (_b==0){
_phase=1;
}
break;
case 1:
_g--;
if (_g==0){
_phase=2;
}
break;
case 2:
_r--;
if (_r==10){
_phase=3;
_steptime=1000;
}
break;
case 3:
_b++;
if (_b==10){
_phase=4;
}
break;
case 4:
_r--;
if (_r==0){
_steptime = 20000;
_phase=5;
}
break;
case 5:
_b--;
if (_b==0){
_steptime = 10000;
_r = 0;
_g = 0;
_b = 0;
_phase=6;
}
break;
case 6:
return;
}
_strip->fill(max(_r,0),max(_g,0),max(_b,0));
}