-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndicator.ino
126 lines (107 loc) · 3.1 KB
/
Indicator.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
117
118
119
120
121
122
123
124
125
126
#define INDICATOR_PIN 13
#define INDICATOR_NUMPIXELS 16
#define BUZZER_PIN 14
Adafruit_NeoPixel indicator(INDICATOR_NUMPIXELS, INDICATOR_PIN, NEO_GRB + NEO_KHZ800);
uint32_t indicatorColor0 = indicator.Color(240, 20, 15);
uint32_t indicatorColor1 = indicator.Color(230, 30, 10);
uint32_t indicatorColor2 = indicator.Color(220, 40, 5);
uint32_t indicatorColor3 = indicator.Color(210, 50, 0);
uint32_t indicatorColor4 = indicator.Color(200, 60, 0);
uint32_t indicatorColor5 = indicator.Color(190, 70, 0);
uint32_t indicatorColor6 = indicator.Color(180, 80, 0);
uint32_t indicatorColor7 = indicator.Color(170, 90, 0);
uint32_t indicatorColor8 = indicator.Color(160, 100, 0);
uint32_t indicatorColor9 = indicator.Color(150, 110, 0);
uint32_t indicatorColor10 = indicator.Color(140, 120, 0);
uint32_t indicatorColor11 = indicator.Color(130, 130, 0);
uint32_t indicatorColor12 = indicator.Color(120, 140, 0);
uint32_t indicatorColor13 = indicator.Color(110, 150, 5);
uint32_t indicatorColor14 = indicator.Color(100, 160, 10);
uint32_t indicatorColor15 = indicator.Color(90, 170, 15);
uint32_t indicatorColorX = indicator.Color(0, 0, 0);
uint32_t indicator_colors[16] = {
indicatorColor0, indicatorColor1, indicatorColor2, indicatorColor3,
indicatorColor4, indicatorColor5, indicatorColor6, indicatorColor7,
indicatorColor8, indicatorColor9, indicatorColor10, indicatorColor11,
indicatorColor12, indicatorColor13, indicatorColor14, indicatorColor15
};
void setupIndicatorColors() {
indicator.begin();
indicator.clear();
indicator.setBrightness(15);
pinMode(BUZZER_PIN, OUTPUT);
}
void indicatorDisplay(float hf) {
int pixels = (hf - 1.4) / 0.1;
if (hf == 0.0) {
blinkOrange();
return;
}
if (hf > 5) {
setAllPixels(indicatorColor15);
return;
}
if (pixels < 0) {
blinkRed();
return;
}
int firstBlack = 0;
while (indicator.getPixelColor(firstBlack) != 0) {
firstBlack++;
}
if (pixels > INDICATOR_NUMPIXELS - 1) {
pixels = INDICATOR_NUMPIXELS - 1;
}
Serial.println(pixels);
Serial.println(firstBlack);
if (firstBlack - 1 <= pixels) {
for (int i = 0; i <= pixels; i++) {
indicator.setPixelColor(i, indicator_colors[i]);
indicator.show();
delay(200);
}
} else {
for (int i = firstBlack; i > pixels; i--) {
indicator.setPixelColor(i, indicatorColorX);
indicator.show();
delay(200);
}
}
}
void blinkOrange() {
for (int i = 0; i < 10; i++) {
setAllPixels(indicatorColorX);
delay(300);
setAllPixels(indicatorColor7);
delay(300);
}
}
void blinkRed() {
for (int i = 0; i < 10; i++) {
tone(BUZZER_PIN, 1000);
setAllPixels(indicatorColor0);
delay(300);
noTone(BUZZER_PIN);
setAllPixels(indicatorColorX);
delay(300);
setAllPixels(indicatorColor0);
}
}
void blinkBlue() {
setBlue();
delay(250);
setBlank();
delay(250);
}
void setAllPixels(int color) {
for (int i = 0; i < INDICATOR_NUMPIXELS; i++) {
indicator.setPixelColor(i, color);
}
indicator.show();
}
void setBlue() {
setAllPixels(indicator.Color(40, 90, 150));
}
void setBlank() {
setAllPixels(indicatorColorX);
}