-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundbox-arduino.ino
43 lines (40 loc) · 1.05 KB
/
soundbox-arduino.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
#include <Bounce2.h>
const int buttonStart = 2;
const int shiftButton = 10;
const int buttonNumber = 11;
bool buttonsPressed[buttonNumber];
Bounce debouncer[buttonNumber];
void setup() {
Serial.begin(9600);
for (int i=0; i<buttonNumber; i++) {
buttonsPressed[i] = false;
debouncer[i] = Bounce();
int buttonPin = i + buttonStart;
pinMode(buttonPin, INPUT_PULLUP);
debouncer[i].attach(buttonPin);
debouncer[i].interval(5);
}
}
void loop(){
debouncer[shiftButton].update();
if (debouncer[shiftButton].read() == LOW){
if (!buttonsPressed[shiftButton]) {
buttonsPressed[shiftButton] = true;
}
} else {
buttonsPressed[shiftButton] = false;
}
for (int i=0; i<buttonNumber-1; i++) {
debouncer[i].update();
if (debouncer[i].read() == LOW){
if (!buttonsPressed[i]) {
buttonsPressed[i] = true;
int value = i;
if (buttonsPressed[shiftButton]) { value += 10; }
Serial.println(value);
}
} else {
buttonsPressed[i] = false;
}
}
}