-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sequence.h
108 lines (98 loc) · 3.05 KB
/
Sequence.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
#ifndef SEQUENCE_H
#define SEQUENCE_H
#include "Led.h"
#include "effects.h"
class Sequence {
public:
Sequence();
int8_t isrunning;
uint32_t start_time;
};
Sequence::Sequence(){
isrunning=0;
start_time=millis();
}
class Heartbeat: public Sequence{
public:
Heartbeat();
void init();
void request_stop();
void request_start();
void tick();
LEDColor up_color,down_color,pulse1_color,pulse2_color;
int rampup_time,rampdown_time,pulse1_time,pulse2_time,wait_time;
float upsplit,downsplit;
private:
uint32_t last_time;
};
Heartbeat::Heartbeat(){
start_time=millis();
isrunning=0;
last_time=0;
up_color=LEDColor(30,30,30);
down_color=LEDColor(30,30,30);
pulse1_color=LEDColor(0,0,0);
pulse2_color=LEDColor(90,90,90);
rampup_time=220;
rampdown_time=330;
pulse1_time=10;
pulse2_time=50;
wait_time=220;
}
void Heartbeat::init(){
start_time=millis();
last_time=0;
}
void Heartbeat::request_stop(){
if(isrunning!=0){
isrunning=0;
}
}
void Heartbeat::request_start(){
if(isrunning==0){
this->init();
isrunning=1;
}
}
void Heartbeat::tick(){
if(isrunning==1&&(millis() != last_time)){
last_time=millis();
float progress;
int running_time=millis()-start_time;
if (running_time < rampup_time){
progress=(float)running_time/(float)rampup_time;
setHeart(up_color.r*progress,up_color.g*progress,up_color.b*progress);
}else if (running_time < (rampup_time+pulse1_time)){
setHeart(pulse1_color.r,pulse1_color.g,pulse1_color.b);
}else if (running_time < (rampup_time+pulse1_time+pulse2_time)){
setHeart(pulse2_color.r,pulse2_color.g,pulse2_color.b);
}else if (running_time < (rampup_time+pulse1_time+pulse2_time+rampdown_time)){
progress=(float)(running_time-(rampup_time+pulse1_time+pulse2_time))/(float)(rampdown_time);
progress=1.0-progress;
setHeart(down_color.r*progress,down_color.g*progress,down_color.b*progress);
}else if (running_time > (rampup_time+pulse1_time+pulse2_time+rampdown_time+wait_time)){
setHeart(0,0,0);
this->request_stop();
this->request_start();
}
stripOutput();
}
}
/* if(isrunning==1){
int running_time=millis()-start_time;
float progress;
if (running_time < rampup_time){
progress=(float)running_time/(float)rampup_time;
}else if (running_time < (rampup_time+pulse1_time)){
//setHeart(pulse1_color.r,pulse1_color.g,pulse1_color.b);
}else if (running_time < (rampup_time+pulse1_time+pulse2_time)){
//setHeart(pulse2_color.r,pulse1_color.g,pulse2_color.b);
}else if (running_time < (rampup_time+pulse1_time+pulse2_time+rampdown_time)){
//progress=(float)(running_time-(rampup_time+pulse1_time+pulse2_time))/(float)(rampdown_time);
}else if (running_time > (rampup_time+pulse1_time+pulse2_time+rampdown_time+wait_time){
setHeart(0,0,0);
this->request_stop();
this->request_start();
}
}*/
#endif //SEQUENCE_H