forked from omriharel/deej
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deej-5-sliders-inverted-with-mute.ino
68 lines (57 loc) · 1.58 KB
/
deej-5-sliders-inverted-with-mute.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
const int NUM_SLIDERS = 5;
const int analogInputs[NUM_SLIDERS] = {A0, A1, A2, A3, A6};
const int digitalInputs[NUM_SLIDERS] = {5, 6, 7, 8, 9};
int analogSliderValues[NUM_SLIDERS];
bool mutedSliders[NUM_SLIDERS];
int mutedTimeout[NUM_SLIDERS];
void setup() {
for (int i = 0; i < NUM_SLIDERS; i++) {
pinMode(analogInputs[i], INPUT);
pinMode(digitalInputs[i], INPUT_PULLUP);
}
Serial.begin(9600);
}
void loop() {
updateSliderValues();
sendSliderValues(); // Actually send data (all the time)
// printSliderValues(); // For debug
delay(10);
}
void updateSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
analogSliderValues[i] = 1023 - analogRead(analogInputs[i]);
if (digitalRead(digitalInputs[i]) == HIGH) {
if (mutedTimeout[i] < 20) {
mutedTimeout[i]++;
}
} else if (mutedTimeout[i] > 10) {
mutedSliders[i] = !mutedSliders[i];
mutedTimeout[i] = 0;
}
}
}
void sendSliderValues() {
String builtString = String("");
for (int i = 0; i < NUM_SLIDERS; i++) {
int val = 0;
if (!mutedSliders[i]) {
val = (int)analogSliderValues[i];
}
builtString += String(val);
if (i < NUM_SLIDERS - 1) {
builtString += String("|");
}
}
Serial.println(builtString);
}
void printSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
String printedString = String("Slider #") + String(i + 1) + String(": ") + String(analogSliderValues[i]) + String(" mV");
Serial.write(printedString.c_str());
if (i < NUM_SLIDERS - 1) {
Serial.write(" | ");
} else {
Serial.write("\n");
}
}
}