![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Dependencies: BLE_API mbed BLE_nRF8001 DebounceIn
main.cpp
- Committer:
- sitakumar
- Date:
- 2015-03-21
- Revision:
- 2:f266f102ca80
- Parent:
- 0:adcc621e5713
- Child:
- 3:b3153fd49501
File content as of revision 2:f266f102ca80:
#include "mbed.h" //#include "DebounceIn.h" #include "BLEPeripheral.h" Serial serial(USBTX, USBRX); // The SPI construct, REQN and RDYN IO construct should be modified manually // It depend on the board you are using and the REQN&RDYN configuration on BLE Shield SPI spi(PTD2, PTD3, PTD1); DigitalInOut BLE_RDY(PTD5); DigitalInOut BLE_REQ(PTD0); DigitalInOut BLE_RESET(PTA13); DigitalIn pb(D4); int count = 0; unsigned char txbuf[16] = {0}; unsigned char txlen = 0; /*----- BLE Utility -------------------------------------------------------------------------*/ // create peripheral instance, see pinouts above BLEPeripheral blePeripheral = BLEPeripheral(&BLE_REQ, &BLE_RDY, NULL); // create service BLEService uartService = BLEService("713d0000503e4c75ba943148f18d941e"); // create characteristic BLECharacteristic txCharacteristic = BLECharacteristic("713d0002503e4c75ba943148f18d941e", BLENotify, 20); BLECharacteristic rxCharacteristic = BLECharacteristic("713d0003503e4c75ba943148f18d941e", BLEWriteWithoutResponse, 20); /*--------------------------------------------------------------------------------------------*/ unsigned int interval = 0; unsigned char count_on = 0; int main() { serial.printf("Hello SmartD!\n"); //serial.baud(115200); serial.printf("Serial begin!\r\n"); pb.mode(PullUp); wait(.001); /*----- BLE Utility ---------------------------------------------*/ // set advertised local name and service UUID blePeripheral.setLocalName("Sita"); blePeripheral.setAdvertisedServiceUuid(uartService.uuid()); // add service and characteristic blePeripheral.addAttribute(uartService); blePeripheral.addAttribute(rxCharacteristic); blePeripheral.addAttribute(txCharacteristic); // begin initialization blePeripheral.begin(); /*---------------------------------------------------------------*/ serial.printf("BLE UART Peripheral begin!\r\n"); while(1) { BLECentral central = blePeripheral.central(); if (central) { // central connected to peripheral serial.printf("Connected to central\r\n"); while (central.connected()) { // central still connected to peripheral if (!pb) { count++; wait(.5); //serial.printf("%d",count); } if(count>0) {serial.printf("button pressed\r\n"); count = 0; wait (.5);} } } // central disconnected else { serial.printf("Disconnected from central\r\n"); } } }