Sample Eddystone Beacon Switch Code (Seeed Platform)
Dependencies: BLE_API mbed nRF51822
Diff: main.cpp
- Revision:
- 2:fc105f4c854e
- Parent:
- 0:fb6bbc10ffa0
- Child:
- 3:bfd6f56605d7
--- a/main.cpp Sun Jan 01 20:57:57 2012 +0000 +++ b/main.cpp Sat Sep 26 00:08:25 2015 +0000 @@ -1,12 +1,58 @@ #include "mbed.h" +#include "BLEDevice.h" +#include "DeviceInformationService.h" + + +InterruptIn button1(P0_17); +InterruptIn mysw1(P0_18); +DigitalOut myled1(P0_12); +DigitalOut myled2(P0_15); +DigitalOut myled3(P0_16); +// Serial pc(USBTX,USBRX); +int count = 0; +int flag = false; -DigitalOut myled(LED1); +// Callback for button1 +void handle_sensor() { + count++; + myled2 = !myled2; +} + +void handle_sw1() { + flag = !flag; + } + + +void ledflasher() { + myled1 = 1; + wait(0.3); + myled1 = 0; + myled2 = 1; + wait(0.3); + myled2 = 0; + myled3 = 1; + wait(0.4); + myled3 = 0; + } int main() { + // Initialize button1 and pull up + // set interrupt callback for button1 + button1.fall(&handle_sensor); + mysw1.fall(&handle_sw1); + button1.mode(PullUp); + mysw1.mode(PullUp); + myled1 = 0; + myled2 = 0; + myled3 = 0; + while(1) { - myled = 1; - wait(0.2); - myled = 0; + if (flag) { + ledflasher(); + } wait(0.2); } + + + }