-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.ino
30 lines (27 loc) · 1.09 KB
/
volume.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
#include "Dot.h"
int currentMode = -1;
const int VOLUME_MARGIN = 8;
const int VOLUME_MIN = 0;
const int BORDER_BL = 30;
const int BORDER_LU = 341;
const int BORDER_UR = 682;
const int BORDER_RB = 993;
const int VOLUME_MAX = 1023;
void volume() {
int mode = getMode();
if (currentMode != mode || currentMode==-1) {
if (currentMode != -1) sound(VOLUME);
Serial.println(getMode());
delay(30);
currentMode = mode;
}
}
int getMode() {
float value = analogRead(VOLUME);
if ( VOLUME_MIN <= value&&value < BORDER_BL -VOLUME_MARGIN) return 2;
else if (VOLUME_MARGIN+ BORDER_BL < value&&value < BORDER_LU -VOLUME_MARGIN) return 3;
else if (VOLUME_MARGIN+ BORDER_LU < value&&value < BORDER_UR -VOLUME_MARGIN) return 1;
else if (VOLUME_MARGIN+ BORDER_UR < value&&value < BORDER_RB -VOLUME_MARGIN) return 4;
else if (VOLUME_MARGIN+ BORDER_RB < value&&value <= VOLUME_MAX) return 2;
else return -1;
}