diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino b/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino index 00c1805a..a7fc2559 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino @@ -19,41 +19,34 @@ */ #include +#include // max concurrent connections supported by this example #define MAX_PRPH_CONNECTION 2 uint8_t connection_count = 0; -/* HRM Service Definitions - * Heart Rate Monitor Service: 0x180D - * Heart Rate Measurement Char: 0x2A37 - * Body Sensor Location Char: 0x2A38 - */ -BLEService hrms = BLEService(UUID16_SVC_HEART_RATE); -BLECharacteristic hrmc = BLECharacteristic(UUID16_CHR_HEART_RATE_MEASUREMENT); -BLECharacteristic bslc = BLECharacteristic(UUID16_CHR_BODY_SENSOR_LOCATION); - -/* LBS Service: 00001523-1212-EFDE-1523-785FEABCD123 +/* Nordic Led-Button Service (LBS) + * LBS Service: 00001523-1212-EFDE-1523-785FEABCD123 * LBS Button : 00001524-1212-EFDE-1523-785FEABCD123 * LBS LED : 00001525-1212-EFDE-1523-785FEABCD123 */ const uint8_t LBS_UUID_SERVICE[] = { - 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, - 0xDE, 0xEF, 0x12, 0x12, 0x23, 0x15, 0x00, 0x00 + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, 0x23, 0x15, 0x00, 0x00 }; const uint8_t LBS_UUID_CHR_BUTTON[] = { - 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, - 0xDE, 0xEF, 0x12, 0x12, 0x24, 0x15, 0x00, 0x00 + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, 0x24, 0x15, 0x00, 0x00 }; const uint8_t LBS_UUID_CHR_LED[] = { - 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, - 0xDE, 0xEF, 0x12, 0x12, 0x25, 0x15, 0x00, 0x00 + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, 0x25, 0x15, 0x00, 0x00 }; BLEService lbs(LBS_UUID_SERVICE); @@ -67,15 +60,36 @@ BLECharacteristic lsbLED(LBS_UUID_CHR_LED); uint8_t button = A0; #endif +// CPB button active state is HIGH, all other is low +#ifdef ARDUINO_NRF52840_CIRCUITPLAY + #define BUTTON_ACTIVE HIGH +#else + #define BUTTON_ACTIVE LOW +#endif + uint8_t buttonState; +#ifdef PIN_NEOPIXEL + +#ifndef NEOPIXEL_NUM +#define NEOPIXEL_NUM 1 +#endif + +Adafruit_NeoPixel neopixel = Adafruit_NeoPixel(NEOPIXEL_NUM, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); + +#endif + void setup() { + pinMode(button, BUTTON_ACTIVE ? INPUT_PULLDOWN : INPUT_PULLUP); + buttonState = (BUTTON_ACTIVE == digitalRead(button)); + pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, 1-LED_STATE_ON); // led off - pinMode(button, INPUT_PULLUP); - buttonState = (uint8_t) (1-digitalRead(button)); // button is active LOW +#ifdef PIN_NEOPIXEL + neopixel.begin(); +#endif Serial.begin(115200); //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 // data = 1 -> LED = On // data = 0 -> LED = Off digitalWrite(LED_BUILTIN, data[0] ? LED_STATE_ON : (1-LED_STATE_ON)); + +#ifdef PIN_NEOPIXEL + uint32_t c = neopixel.Color(0x00, 0x00, data[0] ? 0x20 : 0x00); + neopixel.fill(c, 0, NEOPIXEL_NUM); + neopixel.show(); +#endif } void loop() { delay(10); // poll button every 10 ms - uint8_t newState = (uint8_t) (1-digitalRead(button)); // button is active LOW + uint8_t newState = (BUTTON_ACTIVE == digitalRead(button)); - // only notify if button state chagnes + // only notify if button state changes if ( newState != buttonState) { buttonState = newState; diff --git a/variants/circuitplayground_nrf52840/variant.h b/variants/circuitplayground_nrf52840/variant.h index 2bbadeb0..5624a59b 100644 --- a/variants/circuitplayground_nrf52840/variant.h +++ b/variants/circuitplayground_nrf52840/variant.h @@ -45,6 +45,7 @@ extern "C" // LEDs #define PIN_LED1 (13) #define PIN_NEOPIXEL (8) +#define NEOPIXEL_NUM 10 #define LED_BUILTIN PIN_LED1 diff --git a/variants/clue_nrf52840/variant.h b/variants/clue_nrf52840/variant.h index 7924b3ba..de6db9d6 100644 --- a/variants/clue_nrf52840/variant.h +++ b/variants/clue_nrf52840/variant.h @@ -44,6 +44,7 @@ extern "C" #define PIN_LED1 (17) #define PIN_LED2 (43) // dual white LEDs #define PIN_NEOPIXEL (18) +#define NEOPIXEL_NUM 1 #define LED_BUILTIN PIN_LED1 diff --git a/variants/feather_nrf52840_express/variant.h b/variants/feather_nrf52840_express/variant.h index c64a3728..c4d3d947 100644 --- a/variants/feather_nrf52840_express/variant.h +++ b/variants/feather_nrf52840_express/variant.h @@ -46,6 +46,7 @@ extern "C" #define PIN_LED1 (3) #define PIN_LED2 (4) #define PIN_NEOPIXEL (8) +#define NEOPIXEL_NUM 1 #define LED_BUILTIN PIN_LED1 #define LED_CONN PIN_LED2 diff --git a/variants/feather_nrf52840_sense/variant.h b/variants/feather_nrf52840_sense/variant.h index 18d1782d..210f09a3 100644 --- a/variants/feather_nrf52840_sense/variant.h +++ b/variants/feather_nrf52840_sense/variant.h @@ -45,6 +45,7 @@ extern "C" #define PIN_LED1 (13) #define PIN_LED2 (4) #define PIN_NEOPIXEL (8) +#define NEOPIXEL_NUM 1 #define LED_BUILTIN PIN_LED1 #define LED_CONN PIN_LED2 diff --git a/variants/metro_nrf52840_express/variant.h b/variants/metro_nrf52840_express/variant.h index 852a147c..76904a36 100644 --- a/variants/metro_nrf52840_express/variant.h +++ b/variants/metro_nrf52840_express/variant.h @@ -46,6 +46,7 @@ extern "C" #define PIN_LED1 (33) #define PIN_LED2 (34) #define PIN_NEOPIXEL (35) +#define NEOPIXEL_NUM 1 #define LED_BUILTIN PIN_LED1 #define LED_CONN PIN_LED2