forked from omriharel/deej
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeej-5-sliders-vanilla.ino
69 lines (55 loc) · 1.52 KB
/
deej-5-sliders-vanilla.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
const int NUM_SLIDERS = 5;
const int analogInputs[NUM_SLIDERS] = {A0, A1, A2, A3, A4};
int analogSliderValues[NUM_SLIDERS];
const int JITTER = 3;
int oldSliderValues[NUM_SLIDERS];
bool changed = true; // send values first time
void setup() {
for (int i = 0; i < NUM_SLIDERS; i++) {
pinMode(analogInputs[i], INPUT);
}
Serial.begin(9600);
}
void loop() {
updateSliderValues();
if (changed == true) {
sendSliderValues(); // Actually send data (all the time)
//reset values
for(int i = 0; i < NUM_SLIDERS; i++) {
oldSliderValues[i] = analogSliderValues[i];
}
changed = false;
}
// printSliderValues(); // For debug
delay(10);
}
void updateSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++){
analogSliderValues[i] = analogRead(analogInputs[i]);
//compare for changes
if (abs(analogSliderValues[i] - oldSliderValues[i]) > JITTER){
changed = true;
}
}
}
void sendSliderValues() {
String builtString = String("");
for (int i = 0; i < NUM_SLIDERS; i++) {
builtString += String((int)analogSliderValues[i]);
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");
}
}
}