19
19
*/
20
20
21
21
#include < bluefruit.h>
22
+ #include < Adafruit_NeoPixel.h>
22
23
23
24
// max concurrent connections supported by this example
24
25
#define MAX_PRPH_CONNECTION 2
25
26
uint8_t connection_count = 0 ;
26
27
27
- /* HRM Service Definitions
28
- * Heart Rate Monitor Service: 0x180D
29
- * Heart Rate Measurement Char: 0x2A37
30
- * Body Sensor Location Char: 0x2A38
31
- */
32
- BLEService hrms = BLEService(UUID16_SVC_HEART_RATE);
33
- BLECharacteristic hrmc = BLECharacteristic(UUID16_CHR_HEART_RATE_MEASUREMENT);
34
- BLECharacteristic bslc = BLECharacteristic(UUID16_CHR_BODY_SENSOR_LOCATION);
35
-
36
- /* LBS Service: 00001523-1212-EFDE-1523-785FEABCD123
28
+ /* Nordic Led-Button Service (LBS)
29
+ * LBS Service: 00001523-1212-EFDE-1523-785FEABCD123
37
30
* LBS Button : 00001524-1212-EFDE-1523-785FEABCD123
38
31
* LBS LED : 00001525-1212-EFDE-1523-785FEABCD123
39
32
*/
40
33
41
34
const uint8_t LBS_UUID_SERVICE[] =
42
35
{
43
- 0x23 , 0xD1 , 0xBC , 0xEA , 0x5F , 0x78 , 0x23 , 0x15 ,
44
- 0xDE , 0xEF , 0x12 , 0x12 , 0x23 , 0x15 , 0x00 , 0x00
36
+ 0x23 , 0xD1 , 0xBC , 0xEA , 0x5F , 0x78 , 0x23 , 0x15 ,
37
+ 0xDE , 0xEF , 0x12 , 0x12 , 0x23 , 0x15 , 0x00 , 0x00
45
38
};
46
39
47
40
const uint8_t LBS_UUID_CHR_BUTTON[] =
48
41
{
49
- 0x23 , 0xD1 , 0xBC , 0xEA , 0x5F , 0x78 , 0x23 , 0x15 ,
50
- 0xDE , 0xEF , 0x12 , 0x12 , 0x24 , 0x15 , 0x00 , 0x00
42
+ 0x23 , 0xD1 , 0xBC , 0xEA , 0x5F , 0x78 , 0x23 , 0x15 ,
43
+ 0xDE , 0xEF , 0x12 , 0x12 , 0x24 , 0x15 , 0x00 , 0x00
51
44
};
52
45
53
46
const uint8_t LBS_UUID_CHR_LED[] =
54
47
{
55
- 0x23 , 0xD1 , 0xBC , 0xEA , 0x5F , 0x78 , 0x23 , 0x15 ,
56
- 0xDE , 0xEF , 0x12 , 0x12 , 0x25 , 0x15 , 0x00 , 0x00
48
+ 0x23 , 0xD1 , 0xBC , 0xEA , 0x5F , 0x78 , 0x23 , 0x15 ,
49
+ 0xDE , 0xEF , 0x12 , 0x12 , 0x25 , 0x15 , 0x00 , 0x00
57
50
};
58
51
59
52
BLEService lbs (LBS_UUID_SERVICE);
@@ -67,15 +60,36 @@ BLECharacteristic lsbLED(LBS_UUID_CHR_LED);
67
60
uint8_t button = A0;
68
61
#endif
69
62
63
+ // CPB button active state is HIGH, all other is low
64
+ #ifdef ARDUINO_NRF52840_CIRCUITPLAY
65
+ #define BUTTON_ACTIVE HIGH
66
+ #else
67
+ #define BUTTON_ACTIVE LOW
68
+ #endif
69
+
70
70
uint8_t buttonState;
71
71
72
+ #ifdef PIN_NEOPIXEL
73
+
74
+ #ifndef NEOPIXEL_NUM
75
+ #define NEOPIXEL_NUM 1
76
+ #endif
77
+
78
+ Adafruit_NeoPixel neopixel = Adafruit_NeoPixel(NEOPIXEL_NUM, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
79
+
80
+ #endif
81
+
72
82
void setup ()
73
83
{
84
+ pinMode (button, BUTTON_ACTIVE ? INPUT_PULLDOWN : INPUT_PULLUP);
85
+ buttonState = (BUTTON_ACTIVE == digitalRead (button));
86
+
74
87
pinMode (LED_BUILTIN, OUTPUT);
75
88
digitalWrite (LED_BUILTIN, 1 -LED_STATE_ON); // led off
76
89
77
- pinMode (button, INPUT_PULLUP);
78
- buttonState = (uint8_t ) (1 -digitalRead (button)); // button is active LOW
90
+ #ifdef PIN_NEOPIXEL
91
+ neopixel.begin ();
92
+ #endif
79
93
80
94
Serial.begin (115200 );
81
95
// while ( !Serial ) delay(10); // for nrf52840 with native usb
@@ -162,15 +176,21 @@ void led_write_callback(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data
162
176
// data = 1 -> LED = On
163
177
// data = 0 -> LED = Off
164
178
digitalWrite (LED_BUILTIN, data[0 ] ? LED_STATE_ON : (1 -LED_STATE_ON));
179
+
180
+ #ifdef PIN_NEOPIXEL
181
+ uint32_t c = neopixel.Color (0x00 , 0x00 , data[0 ] ? 0x20 : 0x00 );
182
+ neopixel.fill (c, 0 , NEOPIXEL_NUM);
183
+ neopixel.show ();
184
+ #endif
165
185
}
166
186
167
187
void loop ()
168
188
{
169
189
delay (10 ); // poll button every 10 ms
170
190
171
- uint8_t newState = (uint8_t ) ( 1 - digitalRead (button)); // button is active LOW
191
+ uint8_t newState = (BUTTON_ACTIVE == digitalRead (button));
172
192
173
- // only notify if button state chagnes
193
+ // only notify if button state changes
174
194
if ( newState != buttonState)
175
195
{
176
196
buttonState = newState;
0 commit comments