Sample Eddystone Beacon Switch Code (Seeed Platform)
Dependencies: BLE_API mbed nRF51822
Revision 3:bfd6f56605d7, committed 2015-09-29
- Comitter:
- roywant
- Date:
- Tue Sep 29 23:40:46 2015 +0000
- Parent:
- 2:fc105f4c854e
- Commit message:
- Updated to work with Seeed Arch and Tiny BLE
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r fc105f4c854e -r bfd6f56605d7 main.cpp --- a/main.cpp Sat Sep 26 00:08:25 2015 +0000 +++ b/main.cpp Tue Sep 29 23:40:46 2015 +0000 @@ -2,49 +2,59 @@ #include "BLEDevice.h" #include "DeviceInformationService.h" +#define TINYBLE true +#define SEEEDARCH false + +#if TINYBLE +int ledOn = 0; +int ledOff = 1; + +InterruptIn button1(P0_17); +DigitalOut ledRed(P0_22); +DigitalOut ledGreen(P0_21); +DigitalOut ledBlue(P0_23); +#endif + +#if SEEEDARCH +int ledOn = 1; +int ledOff = 0; 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; +DigitalOut ledRed(P0_12); +DigitalOut ledGreen(P0_15); +DigitalOut ledBlue(P0_16); +#endif + +Serial pc(USBTX,USBRX); int flag = false; -// Callback for button1 -void handle_sensor() { - count++; - myled2 = !myled2; -} - -void handle_sw1() { +void handle_button1() { + printf("button!\r\n"); flag = !flag; } void ledflasher() { - myled1 = 1; + ledGreen = ledOn; wait(0.3); - myled1 = 0; - myled2 = 1; + ledGreen = ledOff; + ledRed = ledOn; wait(0.3); - myled2 = 0; - myled3 = 1; + ledRed = ledOff; + ledBlue = ledOn; wait(0.4); - myled3 = 0; + ledBlue = ledOff; } int main() { // Initialize button1 and pull up // set interrupt callback for button1 - button1.fall(&handle_sensor); - mysw1.fall(&handle_sw1); + button1.fall(&handle_button1); button1.mode(PullUp); - mysw1.mode(PullUp); - myled1 = 0; - myled2 = 0; - myled3 = 0; + ledGreen = ledOff; + ledRed = ledOff; + ledBlue = ledOff; while(1) { if (flag) { @@ -55,4 +65,4 @@ -} +} \ No newline at end of file