-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathBLExaDemo.ino
86 lines (72 loc) · 1.98 KB
/
BLExaDemo.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
79
80
81
82
83
84
85
86
#include "NDP.h"
#include <ArduinoBLE.h>
// BLE Battery Service
BLEService alertService("1802"); // Immediate alert
// BLE Battery Level Characteristic
BLEUnsignedCharCharacteristic alertLevel("2A06", BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
const bool lowestPower = true;
void alertViaBLE(int index) {
// notify that we recognized a keyword
alertLevel.writeValue(2);
delay(1000);
alertLevel.writeValue(0);
}
void ledGreenOn() {
nicla::leds.begin();
nicla::leds.setColor(green);
delay(200);
nicla::leds.setColor(off);
nicla::leds.end();
}
void ledRedBlink() {
while (1) {
nicla::leds.begin();
nicla::leds.setColor(red);
delay(200);
nicla::leds.setColor(off);
delay(200);
nicla::leds.end();
}
}
void setup() {
Serial.begin(115200);
nicla::begin();
nicla::disableLDO();
nicla::leds.begin();
if (!BLE.begin()) {
Serial.println("Starting BLE failed!");
while (1);
}
BLE.setLocalName("BLExaDemo");
BLE.setAdvertisedService(alertService); // add the service UUID
alertService.addCharacteristic(alertLevel); // add the alert level characteristic
BLE.addService(alertService); // Add the alert service
alertLevel.writeValue(0); // set initial value for this characteristic
NDP.onError(ledRedBlink);
NDP.onMatch(alertViaBLE);
NDP.onEvent(ledGreenOn);
NDP.begin("mcu_fw_120_v91.synpkg");
NDP.load("dsp_firmware_v91.synpkg");
NDP.load("alexa_334_NDP120_B0_v11_v91.synpkg");
NDP.turnOnMicrophone();
NDP.interrupts();
// start advertising
BLE.advertise();
// For maximum low power; please note that it's impossible to print afer calling these functions
nicla::leds.end();
if (lowestPower) {
NRF_UART0->ENABLE = 0;
}
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
// serve the updates in the interrupt
while (central.connected()) {
// sleep and save power
delay(1000);
}
} else {
delay(1000);
}
}