-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.ino
86 lines (76 loc) · 2.14 KB
/
utility.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
/**
* Beep!
* onLength = how many MS the beeper will be on
* offLength = how many MS the beeper will be off
* amount = how many times to repeat the beep for
*/
void beep(unsigned long onLength, unsigned long offLength, byte amount) {
unsigned long length = 0;
for(byte i = 0; i < amount * 2; i++) {
if(i % 2 == 0) {
// Beeper should go ON in this stage.
t.in(length, [](void *) -> bool {
digitalWrite(PIN_BEEPER, LOW); // LOW -> ON (active low);
return false; // Don't repeat
});
length += onLength;
}else{
// Beeper should go OFF in this stage.
t.in(length, [](void *) -> bool {
digitalWrite(PIN_BEEPER, HIGH); // HIGH -> OFF (active low);
return false; // Don't repeat
});
length += offLength;
}
}
}
/**
* Beep!
* onOffLength = how many MS the beeper will be on and off
* amount = how many times to repeat the beep for
*/
inline void beep(unsigned long onOffLength, byte amount) {
beep(onOffLength, onOffLength, amount);
}
/**
* Fills the led strip with a certain color
*/
void fillStrip(int r, int g, int b) {
strip.begin();
for(int i = 0; i < STRIP_LENGTH; i++) {
strip.setPixelColor(i, r, g, b);
}
strip.show();
}
/**
* Simple map function with floats
*/
inline float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
/**
* Checks for the reset pattern (* #) on the keypad
*/
String reset_charsEntered = "";
void checkResetKeypadPattern(char justPressed) {
if(justPressed) {
if(reset_charsEntered.length() == 2) {
reset_charsEntered = reset_charsEntered.substring(1);
}
reset_charsEntered += justPressed;
if(reset_charsEntered.charAt(reset_charsEntered.length() - 2) == '*' &&
reset_charsEntered.charAt(reset_charsEntered.length() - 1) == '#') {
// Reset!
// beep(20, 200, 2);
reset();
}
}
}
/**
* Prints a string to the lcd in a centered x position
*/
void lcdPrintCenter(String s, int y) {
int x = LCD_COLS / 2 - ceil(s.length() / 2.0);
lcd.setCursor(x, y);
lcd.print(s);
}