-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConcrete_control.ino
65 lines (46 loc) · 1.2 KB
/
Concrete_control.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
#include <BleKeyboard.h>
#include "Button2.h";
#include "ESPRotary.h";
#define ROTARY_PIN1 22
#define ROTARY_PIN2 14
#define BUTTON_PIN 23
#define CLICKS_PER_STEP 4
ESPRotary r = ESPRotary(ROTARY_PIN1, ROTARY_PIN2, CLICKS_PER_STEP);
Button2 b = Button2(BUTTON_PIN);
BleKeyboard bleKeyboard = BleKeyboard("Concrete Control", "md-tech");
void setup() {
Serial.begin(115200);
Serial.println("BLE active");
bleKeyboard.begin();
r.setChangedHandler(rotate);
b.setTapHandler(click);
b.setLongClickHandler(resetPosition);
}
void loop() {
r.loop();
b.loop();
}
void rotate(ESPRotary& r) {
if (r.getDirection() == RE_RIGHT) {
Serial.println("up");
sendViaBluetooth(KEY_MEDIA_VOLUME_UP);
} else {
Serial.println("down");
sendViaBluetooth(KEY_MEDIA_VOLUME_DOWN);
}
}
void sendViaBluetooth(const MediaKeyReport c){
bleKeyboard.write(c);
bleKeyboard.release(c);
}
void click(Button2& btn) {
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);
bleKeyboard.release(KEY_MEDIA_PLAY_PAUSE);
}
Serial.println("Click");
}
void resetPosition(Button2& btn) {
r.resetPosition();
Serial.println("Reset");
}