forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHID_test.ino
More file actions
67 lines (52 loc) · 1.64 KB
/
HID_test.ino
File metadata and controls
67 lines (52 loc) · 1.64 KB
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
// Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Import libraries (BLEPeripheralObserver depends on SPI)
#include <SPI.h>
#include <BLEHIDPeripheral.h>
#include <BLEMouse.h>
#include <BLEKeyboard.h>
#include <BLEMultimedia.h>
#include <BLESystemControl.h>
//custom boards may override default pin definitions with BLEHIDPeripheral(PIN_REQ, PIN_RDY, PIN_RST)
BLEHIDPeripheral bleHID = BLEHIDPeripheral();
BLEMouse bleMouse;
BLEKeyboard bleKeyboard;
BLEMultimedia bleMultimedia;
BLESystemControl bleSystemControl;
void setup() {
Serial.begin(9600);
#if defined (__AVR_ATmega32U4__)
while(!Serial);
#endif
// clears bond data on every boot
bleHID.clearBondStoreData();
bleHID.setDeviceName("Arduino BLE HID");
// bleHID.setAppearance(961);
bleHID.setLocalName("HID");
bleHID.addHID(bleMouse);
bleHID.addHID(bleKeyboard);
bleHID.addHID(bleMultimedia);
bleHID.addHID(bleSystemControl);
bleHID.begin();
Serial.println(F("BLE HID"));
}
void loop() {
BLECentral central = bleHID.central();
if (central) {
// central connected to peripheral
Serial.print(F("Connected to central: "));
Serial.println(central.address());
while (bleHID.connected()) {
if (Serial.available() > 0) {
Serial.read();
// bleMouse.move(100, 100, 0);
// bleKeyboard.press(KEYCODE_A);
bleMultimedia.write(MMKEY_VOL_UP);
// bleSystemControl.write(SYSCTRLKEY_POWER);
}
}
// central disconnected
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}