Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleControls by
Revision 7:0db51a3107fc, committed 2016-12-15
- Comitter:
- MarkSPA
- Date:
- Thu Dec 15 23:25:16 2016 +0000
- Parent:
- 6:074f5ec7428c
- Child:
- 8:e275405a431d
- Commit message:
- Added a couple of patterns, changed behavior or connect/disconnect.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
patterns.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Dec 09 15:50:13 2016 +0000 +++ b/main.cpp Thu Dec 15 23:25:16 2016 +0000 @@ -55,6 +55,7 @@ #define PATTERN_SNOW 0x08 #define PATTERN_XMAS 0x09 #define PATTERN_ICE 0x0A +#define PATTERN_COL 0x0B #define LEDS_ON 0x01 #define LEDS_OFF 0x02 @@ -80,6 +81,8 @@ uint8_t blue = 159; uint8_t pattern = 0; +char mDeviceName[128]; + uint8_t LEDS_ON_FLAG = 0; // The Nordic UART Service @@ -95,12 +98,14 @@ GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic}; GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); +void setup_advertising(void); void rainbowCycle(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); void candyChase(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); void snowflakes(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip); void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip); +void collegiate(int wait, uint8_t numLEDs, neopixel_strip_t m_strip); extern uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, nrf_radio_notification_distance_t distance, @@ -110,6 +115,7 @@ { neopixel_init(&m_strip, dig_pin_num, NUM_LEDS); neopixel_clear(&m_strip); + LEDS_ON_FLAG = 0; } void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) @@ -119,6 +125,8 @@ //clear and remove strip //neopixel_clear(&m_strip); //neopixel_destroy(&m_strip); + //strcpy(mDeviceName, "RRVA Cntd"); + //setup_advertising(); ble.startAdvertising(); } @@ -239,6 +247,9 @@ else if (pattern == PATTERN_XMAS) xmas(200, NUM_LEDS, m_strip); + else if (pattern == PATTERN_COL) + collegiate(100, NUM_LEDS, m_strip); + else neopixel_clear(&m_strip); @@ -254,6 +265,25 @@ //APP_ERROR_CHECK(err_code); } +void setup_advertising(void) +{ + int length = strlen(mDeviceName); + + // setup advertising + ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); + ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, + (const uint8_t *)&mDeviceName, length); + ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, + (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); + // 100ms; in multiples of 0.625ms. + //ble.setAdvertisingInterval(160); + ble.setAdvertisingInterval(80); + ble.addService(uartService); + ble.startAdvertising(); + //pc.printf("Advertising Start \r\n"); +} + int main(void) { //uint8_t led_error; @@ -274,20 +304,10 @@ //pc.format(8, SerialBase::None, 1); //pc.printf("rbChromaBand Init \r\n"); //pc.attach( uartCB , pc.RxIrq); + + strcpy(mDeviceName, "RRVA BLE"); - // setup advertising - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); - ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, - (const uint8_t *)"rbCtrl02", sizeof("rbCtrl02") - 1); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, - (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); - // 100ms; in multiples of 0.625ms. - //ble.setAdvertisingInterval(160); - ble.setAdvertisingInterval(80); - ble.addService(uartService); - ble.startAdvertising(); - //pc.printf("Advertising Start \r\n"); + setup_advertising(); while(1) { //pc.putc(pc.getc());
--- a/patterns.cpp Fri Dec 09 15:50:13 2016 +0000 +++ b/patterns.cpp Thu Dec 15 23:25:16 2016 +0000 @@ -23,14 +23,13 @@ } void rainbowCycle(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { - uint16_t i, j; - uint32_t ret; + uint16_t i, j; + uint32_t ret; - for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel - for(i=0; i< numLEDs; i++) { - //neopixel_set_color(&m_strip, i, red, green, blue); - //strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); - ret = Wheel(i, m_strip, ((i * 256 / numLEDs) + j & 255)); + for(j=0; j<256; j++) { + for(i=0; i<numLEDs; i++) { + //neopixel_set_color(&m_strip, i, Wheel((i+j) & 255)); + ret = Wheel((i+j) & 255, m_strip, i); } neopixel_show(&m_strip); wait_ms(delay); @@ -74,6 +73,30 @@ } } +void collegiate(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { + + for (int i=0; i < numLEDs; i++) + neopixel_set_color(&m_strip, i, 224,193,36); //turn every pixel gold + + for (int i=0; i < numLEDs-1; i++) { + neopixel_set_color(&m_strip, i, 224,193,36); + neopixel_set_color(&m_strip, i+1, 0,255,0); //turn on a green pixel and move it + neopixel_show(&m_strip); + wait_ms(delay); + } + wait_ms(delay); + + for (int i=0; i < numLEDs; i++) + neopixel_set_color(&m_strip, i, 0,255,0); //turn every pixel green + + for (int i=0; i < numLEDs-1; i++) { + neopixel_set_color(&m_strip, i, 0,255,0); + neopixel_set_color(&m_strip, i+1, 224,193,36); //turn on a gold pixel and move it + neopixel_show(&m_strip); + wait_ms(delay); + } +} + void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) { for (int i=0; i < numLEDs; i++) @@ -90,12 +113,12 @@ for (int j=0; j<numLEDs; j++) neopixel_set_color(&m_strip, j, 0,255,0); neopixel_show(&m_strip); - wait_ms(500); + wait_ms(1000); //All red for (int j=0; j<numLEDs; j++) neopixel_set_color(&m_strip, j, 255,0,0); neopixel_show(&m_strip); - wait_ms(delay); + wait_ms(1000); //Green with a red mover for (int j=0; j<numLEDs; j++) neopixel_set_color(&m_strip, j, 0,255,0);