-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchristmasTreeLights.ino
116 lines (99 loc) · 1.67 KB
/
christmasTreeLights.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
int IN1=9;
int IN2=8;
int ENA=10;
int MIN=10;
int color = 0;
int state = 1;
void ChangeWhite() {
// This is white mode
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
}
void ChangeColor() {
// This is color mode
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
}
void ChangeState() {
if(color==1) {
ChangeWhite();
color = 0;
}
else {
ChangeColor();
color = 1;
}
}
void setup() {
// put your setup code here, to run once:
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(ENA,OUTPUT);
if(color) {
ChangeColor();
}
else {
ChangeWhite();
}
int i = 0;
for(i = 0 ; i <= MIN; i+=1) {
analogWrite(ENA, i);
delay(5);
}
}
void DelayAdjustment(int index) {
float b = 40;
float endValue = 20;
float mLinear = (endValue - b) / 255;
float mExp = (endValue - b) / pow(255,2);
// float delayValue = endValue; // Fixed
// float delayValue = mLinear * index + b; // Linear
float delayValue = mExp* pow(index, 2) + b; // Exponential
delay(int(delayValue));
}
void Brighten() {
int i = 0;
for(i = MIN ; i <= 255; i+=1) {
analogWrite(ENA, i);
DelayAdjustment(i);
}
}
void Dim() {
int i = 0;
for(i = 255; i >=MIN; i-=1) {
analogWrite(ENA, i);
DelayAdjustment(i);
}
}
void Blinking() {
Brighten();
delay(10000);
Dim();
delay(5000);
}
void SwitchBlinking() {
Brighten();
delay(10000);
Dim();
delay(5000);
ChangeState();
Brighten();
delay(10000);
Dim();
delay(5000);
ChangeState();
}
void Solid() {
analogWrite(ENA, 255);
}
void loop() {
if(state == 0) {
Blinking();
}
else if(state==1) {
SwitchBlinking();
}
else {
Solid();
}
}