Skip to content

Commit 88ccb29

Browse files
committed
add NEOPIXEL_NUM to variant.h
minor update the nrf_blinky sketch
1 parent 9ca02a6 commit 88ccb29

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,34 @@
1919
*/
2020

2121
#include <bluefruit.h>
22+
#include <Adafruit_NeoPixel.h>
2223

2324
// max concurrent connections supported by this example
2425
#define MAX_PRPH_CONNECTION 2
2526
uint8_t connection_count = 0;
2627

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
3730
* LBS Button : 00001524-1212-EFDE-1523-785FEABCD123
3831
* LBS LED : 00001525-1212-EFDE-1523-785FEABCD123
3932
*/
4033

4134
const uint8_t LBS_UUID_SERVICE[] =
4235
{
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
4538
};
4639

4740
const uint8_t LBS_UUID_CHR_BUTTON[] =
4841
{
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
5144
};
5245

5346
const uint8_t LBS_UUID_CHR_LED[] =
5447
{
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
5750
};
5851

5952
BLEService lbs(LBS_UUID_SERVICE);
@@ -67,15 +60,36 @@ BLECharacteristic lsbLED(LBS_UUID_CHR_LED);
6760
uint8_t button = A0;
6861
#endif
6962

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+
7070
uint8_t buttonState;
7171

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+
7282
void setup()
7383
{
84+
pinMode(button, BUTTON_ACTIVE ? INPUT_PULLDOWN : INPUT_PULLUP);
85+
buttonState = (BUTTON_ACTIVE == digitalRead(button));
86+
7487
pinMode(LED_BUILTIN, OUTPUT);
7588
digitalWrite(LED_BUILTIN, 1-LED_STATE_ON); // led off
7689

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
7993

8094
Serial.begin(115200);
8195
//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
162176
// data = 1 -> LED = On
163177
// data = 0 -> LED = Off
164178
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
165185
}
166186

167187
void loop()
168188
{
169189
delay(10); // poll button every 10 ms
170190

171-
uint8_t newState = (uint8_t) (1-digitalRead(button)); // button is active LOW
191+
uint8_t newState = (BUTTON_ACTIVE == digitalRead(button));
172192

173-
// only notify if button state chagnes
193+
// only notify if button state changes
174194
if ( newState != buttonState)
175195
{
176196
buttonState = newState;

variants/circuitplayground_nrf52840/variant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern "C"
4545
// LEDs
4646
#define PIN_LED1 (13)
4747
#define PIN_NEOPIXEL (8)
48+
#define NEOPIXEL_NUM 10
4849

4950
#define LED_BUILTIN PIN_LED1
5051

variants/clue_nrf52840/variant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern "C"
4444
#define PIN_LED1 (17)
4545
#define PIN_LED2 (43) // dual white LEDs
4646
#define PIN_NEOPIXEL (18)
47+
#define NEOPIXEL_NUM 1
4748

4849
#define LED_BUILTIN PIN_LED1
4950

variants/feather_nrf52840_express/variant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern "C"
4646
#define PIN_LED1 (3)
4747
#define PIN_LED2 (4)
4848
#define PIN_NEOPIXEL (8)
49+
#define NEOPIXEL_NUM 1
4950

5051
#define LED_BUILTIN PIN_LED1
5152
#define LED_CONN PIN_LED2

variants/feather_nrf52840_sense/variant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern "C"
4545
#define PIN_LED1 (13)
4646
#define PIN_LED2 (4)
4747
#define PIN_NEOPIXEL (8)
48+
#define NEOPIXEL_NUM 1
4849

4950
#define LED_BUILTIN PIN_LED1
5051
#define LED_CONN PIN_LED2

variants/metro_nrf52840_express/variant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern "C"
4646
#define PIN_LED1 (33)
4747
#define PIN_LED2 (34)
4848
#define PIN_NEOPIXEL (35)
49+
#define NEOPIXEL_NUM 1
4950

5051
#define LED_BUILTIN PIN_LED1
5152
#define LED_CONN PIN_LED2

0 commit comments

Comments
 (0)