Sample Eddystone Beacon Switch Code (Seeed Platform)
Dependencies: BLE_API mbed nRF51822
main.cpp@3:bfd6f56605d7, 2015-09-29 (annotated)
- Committer:
- roywant
- Date:
- Tue Sep 29 23:40:46 2015 +0000
- Revision:
- 3:bfd6f56605d7
- Parent:
- 2:fc105f4c854e
Updated to work with Seeed Arch and Tiny BLE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:fb6bbc10ffa0 | 1 | #include "mbed.h" |
roywant | 2:fc105f4c854e | 2 | #include "BLEDevice.h" |
roywant | 2:fc105f4c854e | 3 | #include "DeviceInformationService.h" |
roywant | 2:fc105f4c854e | 4 | |
roywant | 3:bfd6f56605d7 | 5 | #define TINYBLE true |
roywant | 3:bfd6f56605d7 | 6 | #define SEEEDARCH false |
roywant | 3:bfd6f56605d7 | 7 | |
roywant | 3:bfd6f56605d7 | 8 | #if TINYBLE |
roywant | 3:bfd6f56605d7 | 9 | int ledOn = 0; |
roywant | 3:bfd6f56605d7 | 10 | int ledOff = 1; |
roywant | 3:bfd6f56605d7 | 11 | |
roywant | 3:bfd6f56605d7 | 12 | InterruptIn button1(P0_17); |
roywant | 3:bfd6f56605d7 | 13 | DigitalOut ledRed(P0_22); |
roywant | 3:bfd6f56605d7 | 14 | DigitalOut ledGreen(P0_21); |
roywant | 3:bfd6f56605d7 | 15 | DigitalOut ledBlue(P0_23); |
roywant | 3:bfd6f56605d7 | 16 | #endif |
roywant | 3:bfd6f56605d7 | 17 | |
roywant | 3:bfd6f56605d7 | 18 | #if SEEEDARCH |
roywant | 3:bfd6f56605d7 | 19 | int ledOn = 1; |
roywant | 3:bfd6f56605d7 | 20 | int ledOff = 0; |
roywant | 2:fc105f4c854e | 21 | |
roywant | 2:fc105f4c854e | 22 | InterruptIn button1(P0_17); |
roywant | 2:fc105f4c854e | 23 | InterruptIn mysw1(P0_18); |
roywant | 3:bfd6f56605d7 | 24 | DigitalOut ledRed(P0_12); |
roywant | 3:bfd6f56605d7 | 25 | DigitalOut ledGreen(P0_15); |
roywant | 3:bfd6f56605d7 | 26 | DigitalOut ledBlue(P0_16); |
roywant | 3:bfd6f56605d7 | 27 | #endif |
roywant | 3:bfd6f56605d7 | 28 | |
roywant | 3:bfd6f56605d7 | 29 | Serial pc(USBTX,USBRX); |
roywant | 2:fc105f4c854e | 30 | int flag = false; |
simon | 0:fb6bbc10ffa0 | 31 | |
roywant | 3:bfd6f56605d7 | 32 | void handle_button1() { |
roywant | 3:bfd6f56605d7 | 33 | printf("button!\r\n"); |
roywant | 2:fc105f4c854e | 34 | flag = !flag; |
roywant | 2:fc105f4c854e | 35 | } |
roywant | 2:fc105f4c854e | 36 | |
roywant | 2:fc105f4c854e | 37 | |
roywant | 2:fc105f4c854e | 38 | void ledflasher() { |
roywant | 3:bfd6f56605d7 | 39 | ledGreen = ledOn; |
roywant | 2:fc105f4c854e | 40 | wait(0.3); |
roywant | 3:bfd6f56605d7 | 41 | ledGreen = ledOff; |
roywant | 3:bfd6f56605d7 | 42 | ledRed = ledOn; |
roywant | 2:fc105f4c854e | 43 | wait(0.3); |
roywant | 3:bfd6f56605d7 | 44 | ledRed = ledOff; |
roywant | 3:bfd6f56605d7 | 45 | ledBlue = ledOn; |
roywant | 2:fc105f4c854e | 46 | wait(0.4); |
roywant | 3:bfd6f56605d7 | 47 | ledBlue = ledOff; |
roywant | 2:fc105f4c854e | 48 | } |
simon | 0:fb6bbc10ffa0 | 49 | |
simon | 0:fb6bbc10ffa0 | 50 | int main() { |
roywant | 2:fc105f4c854e | 51 | // Initialize button1 and pull up |
roywant | 2:fc105f4c854e | 52 | // set interrupt callback for button1 |
roywant | 3:bfd6f56605d7 | 53 | button1.fall(&handle_button1); |
roywant | 2:fc105f4c854e | 54 | button1.mode(PullUp); |
roywant | 3:bfd6f56605d7 | 55 | ledGreen = ledOff; |
roywant | 3:bfd6f56605d7 | 56 | ledRed = ledOff; |
roywant | 3:bfd6f56605d7 | 57 | ledBlue = ledOff; |
roywant | 2:fc105f4c854e | 58 | |
simon | 0:fb6bbc10ffa0 | 59 | while(1) { |
roywant | 2:fc105f4c854e | 60 | if (flag) { |
roywant | 2:fc105f4c854e | 61 | ledflasher(); |
roywant | 2:fc105f4c854e | 62 | } |
simon | 0:fb6bbc10ffa0 | 63 | wait(0.2); |
simon | 0:fb6bbc10ffa0 | 64 | } |
roywant | 2:fc105f4c854e | 65 | |
roywant | 2:fc105f4c854e | 66 | |
roywant | 2:fc105f4c854e | 67 | |
roywant | 3:bfd6f56605d7 | 68 | } |