Example program for BLE devices using updated Puck library.

Dependencies:   Puck mbed

Fork of location-puck by Nordic Pucks

main.cpp

Committer:
cristea
Date:
2014-06-19
Revision:
4:4324d5acd5d8
Parent:
3:4cb285fb29e7
Child:
5:8ccb1cd6694d

File content as of revision 4:4324d5acd5d8:

#include <mbed.h>
#include <nRF51822n.h>
#define DEBUG 1

#ifdef DEBUG
    Serial pc(USBTX, USBRX);
    #define LOG(args...)    pc.printf(args)
#else
    #define LOG(args...)
#endif

nRF51822n nrf;
DigitalOut led1(p1);
DigitalOut advertisingStateLed(p30);

GapAdvertisingData advData;
GapAdvertisingData scanResponse;
GapAdvertisingParams advParams(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);

int main(void) {

    nrf.init();
    nrf.reset();

    advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    advData.addData(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                    (uint8_t*)"phlemz", sizeof("phlemz") - 1);
    advData.addAppearance(GapAdvertisingData::UNKNOWN);
    nrf.getGap().setAdvertisingData(advData, scanResponse);

    nrf.getGap().startAdvertising(advParams);

    for(;;) {
        led1 = !led1;
        wait(1);
    }
}