-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeanFS.ino
78 lines (68 loc) · 1.83 KB
/
BeanFS.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
70
71
72
73
74
75
76
77
78
// LightBlue Bean or Bean+
#define CHANNEL CHANNEL10
#define RNG_CONTROLLER GENERALPURPOSECONTROLLER6
#define TIP_CONTROLLER GENERALPURPOSECONTROLLER5
// TRS jack breakout connected to pins D0..D5
#define TIP_PIN 0
#define RNG_PIN 2
#define SLV_PIN 4
bool connected;
int rngInitState;
int rngLastState;
int tipInitState;
int tipLastState;
void setup() {
// Configure tip and ring pins as digital input with pull-up resistor
pinMode(RNG_PIN, INPUT_PULLUP);
pinMode(TIP_PIN, INPUT_PULLUP);
// Configure sleave pin as ground
pinMode(SLV_PIN, OUTPUT);
digitalWrite(SLV_PIN, LOW);
connected = false;
// LED is blue until we're connected
Bean.setLedBlue(255);
BeanMidi.enable();
}
void loop() {
// connection
if (Bean.getConnectionState() != connected) {
connected = !connected;
if (connected) {
// Read initial pin states
rngInitState = digitalRead(RNG_PIN);
rngLastState = rngInitState;
tipInitState = digitalRead(TIP_PIN);
tipLastState = tipInitState;
Bean.setLedBlue(0);
} else {
Bean.setLedBlue(255);
}
}
if (!connected) {
return;
}
// ring
int rngState = digitalRead(RNG_PIN);
if (rngState != rngLastState) {
rngLastState = rngState;
if (rngState != rngInitState) {
Bean.setLedRed(255);
BeanMidi.sendMessage(CONTROLCHANGE + CHANNEL, RNG_CONTROLLER, 127);
} else {
Bean.setLedRed(0);
BeanMidi.sendMessage(CONTROLCHANGE + CHANNEL, RNG_CONTROLLER, 0);
}
}
// tip
int tipState = digitalRead(TIP_PIN);
if (tipState != tipLastState) {
tipLastState = tipState;
if (tipState != tipInitState) {
Bean.setLedGreen(255);
BeanMidi.sendMessage(CONTROLCHANGE + CHANNEL, TIP_CONTROLLER, 127);
} else {
Bean.setLedGreen(0);
BeanMidi.sendMessage(CONTROLCHANGE + CHANNEL, TIP_CONTROLLER, 0);
}
}
}