-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglove.ino
41 lines (31 loc) · 927 Bytes
/
glove.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
#include <Arduino_APDS9960.h>
#include <BLEMIDI_Transport.h>
#include <hardware/BLEMIDI_ArduinoBLE.h>
BLEMIDI_CREATE_INSTANCE("Glove", MIDI)
unsigned long t0 = millis();
bool isBluetoothConnected = false;
void setup() {
MIDI.begin();
int proximityInitialized = APDS.begin();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
BLEMIDI.setHandleConnected([]() {
isBluetoothConnected = true;
digitalWrite(LED_BUILTIN, HIGH);
});
BLEMIDI.setHandleDisconnected([]() {
isBluetoothConnected = false;
digitalWrite(LED_BUILTIN, LOW);
});
}
void loop() {
const int SENSOR_INTERVAL = 50;
MIDI.read();
if (isBluetoothConnected && APDS.proximityAvailable() &&
(millis() - t0) > SENSOR_INTERVAL) {
t0 = millis();
// `proximity` ranges from 0 (closest) to 255 (farthest)
int proximity = APDS.readProximity();
MIDI.sendControlChange(32, proximity / 2, 1);
}
}