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 UART_TEMPLATE by
main.cpp
00001 00002 00003 #include "mbed.h" 00004 #include "BLEDevice.h" 00005 00006 00007 #define SENSOR_READ_INTERVAL_S (0.5F) 00008 #define ADV_INTERVAL_MS (1000UL) 00009 #define DEVICE_NAME ("SOYNORDIC") // This can be read AFTER connecting to the device. 00010 #define SHORT_NAME ("HACKDEMO") // Keep this short: max 8 chars if a 128bit UUID is also advertised. 00011 00012 00013 DigitalOut led1(LED1); 00014 DigitalOut led2(LED2); 00015 BLEDevice m_ble; 00016 00017 00018 00019 00020 00021 00022 00023 /** 00024 * This callback is scheduled to be called periodically via a low-priority interrupt. 00025 */ 00026 void periodicCallback(void) 00027 { 00028 led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ 00029 led2 = !led2; 00030 } 00031 00032 00033 00034 00035 int main(void) 00036 { 00037 Ticker ticker; 00038 00039 00040 00041 ticker.attach(periodicCallback, SENSOR_READ_INTERVAL_S); 00042 00043 m_ble.init(); 00044 00045 // Set the TX power in dBm units. 00046 // Possible values (in decreasing order): 4, 0, -4, -8, -12, -16, -20. 00047 m_ble.setTxPower(4); 00048 00049 00050 // Setup advertising (GAP stuff). 00051 m_ble.setDeviceName(DEVICE_NAME); 00052 m_ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); 00053 00054 m_ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); 00055 00056 m_ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, 00057 (const uint8_t *)SHORT_NAME, 00058 (sizeof(SHORT_NAME) - 1)); 00059 00060 00061 00062 m_ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADV_INTERVAL_MS)); 00063 m_ble.startAdvertising(); 00064 00065 00066 while (true) { 00067 m_ble.waitForEvent(); 00068 } 00069 }
Generated on Fri Jul 15 2022 10:19:35 by
1.7.2
