-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.cpp
55 lines (42 loc) · 871 Bytes
/
menu.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
#include "menu.h"
#include <Bounce2.h>
#include <EEPROM.h>
bool modeSelect(Bounce &forward, Bounce &backward, int &mode, const int num_modes) {
forward.update();
backward.update();
bool updated = false;
if(forward.rose()) {
mode++;
updated = true;
} else if (backward.rose()) {
mode--;
updated = true;
}
if(mode < 0) {
mode = num_modes - 1;
}
if(mode >= num_modes) {
mode = 0;
}
return updated;
}
bool dimmer(unsigned char down, unsigned char up, int &brightness) {
bool updated = false;
if(digitalRead(down) == LOW) {
brightness -= 1;
updated = true;
}
if(digitalRead(up) == LOW) {
brightness += 1;
updated = true;
}
if(brightness < 0) {
brightness = 0;
updated = true;
}
if(brightness > 255) {
brightness = 255;
updated = true;
}
return updated;
}