Sample Eddystone Beacon Switch Code (Seeed Platform)
Dependencies: BLE_API mbed nRF51822
main.cpp@2:fc105f4c854e, 2015-09-26 (annotated)
- Committer:
- roywant
- Date:
- Sat Sep 26 00:08:25 2015 +0000
- Revision:
- 2:fc105f4c854e
- Parent:
- 0:fb6bbc10ffa0
- Child:
- 3:bfd6f56605d7
Example Switch/Led Code for Eddystone Seed Beacon
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 | 2:fc105f4c854e | 5 | |
roywant | 2:fc105f4c854e | 6 | InterruptIn button1(P0_17); |
roywant | 2:fc105f4c854e | 7 | InterruptIn mysw1(P0_18); |
roywant | 2:fc105f4c854e | 8 | DigitalOut myled1(P0_12); |
roywant | 2:fc105f4c854e | 9 | DigitalOut myled2(P0_15); |
roywant | 2:fc105f4c854e | 10 | DigitalOut myled3(P0_16); |
roywant | 2:fc105f4c854e | 11 | // Serial pc(USBTX,USBRX); |
roywant | 2:fc105f4c854e | 12 | int count = 0; |
roywant | 2:fc105f4c854e | 13 | int flag = false; |
simon | 0:fb6bbc10ffa0 | 14 | |
roywant | 2:fc105f4c854e | 15 | // Callback for button1 |
roywant | 2:fc105f4c854e | 16 | void handle_sensor() { |
roywant | 2:fc105f4c854e | 17 | count++; |
roywant | 2:fc105f4c854e | 18 | myled2 = !myled2; |
roywant | 2:fc105f4c854e | 19 | } |
roywant | 2:fc105f4c854e | 20 | |
roywant | 2:fc105f4c854e | 21 | void handle_sw1() { |
roywant | 2:fc105f4c854e | 22 | flag = !flag; |
roywant | 2:fc105f4c854e | 23 | } |
roywant | 2:fc105f4c854e | 24 | |
roywant | 2:fc105f4c854e | 25 | |
roywant | 2:fc105f4c854e | 26 | void ledflasher() { |
roywant | 2:fc105f4c854e | 27 | myled1 = 1; |
roywant | 2:fc105f4c854e | 28 | wait(0.3); |
roywant | 2:fc105f4c854e | 29 | myled1 = 0; |
roywant | 2:fc105f4c854e | 30 | myled2 = 1; |
roywant | 2:fc105f4c854e | 31 | wait(0.3); |
roywant | 2:fc105f4c854e | 32 | myled2 = 0; |
roywant | 2:fc105f4c854e | 33 | myled3 = 1; |
roywant | 2:fc105f4c854e | 34 | wait(0.4); |
roywant | 2:fc105f4c854e | 35 | myled3 = 0; |
roywant | 2:fc105f4c854e | 36 | } |
simon | 0:fb6bbc10ffa0 | 37 | |
simon | 0:fb6bbc10ffa0 | 38 | int main() { |
roywant | 2:fc105f4c854e | 39 | // Initialize button1 and pull up |
roywant | 2:fc105f4c854e | 40 | // set interrupt callback for button1 |
roywant | 2:fc105f4c854e | 41 | button1.fall(&handle_sensor); |
roywant | 2:fc105f4c854e | 42 | mysw1.fall(&handle_sw1); |
roywant | 2:fc105f4c854e | 43 | button1.mode(PullUp); |
roywant | 2:fc105f4c854e | 44 | mysw1.mode(PullUp); |
roywant | 2:fc105f4c854e | 45 | myled1 = 0; |
roywant | 2:fc105f4c854e | 46 | myled2 = 0; |
roywant | 2:fc105f4c854e | 47 | myled3 = 0; |
roywant | 2:fc105f4c854e | 48 | |
simon | 0:fb6bbc10ffa0 | 49 | while(1) { |
roywant | 2:fc105f4c854e | 50 | if (flag) { |
roywant | 2:fc105f4c854e | 51 | ledflasher(); |
roywant | 2:fc105f4c854e | 52 | } |
simon | 0:fb6bbc10ffa0 | 53 | wait(0.2); |
simon | 0:fb6bbc10ffa0 | 54 | } |
roywant | 2:fc105f4c854e | 55 | |
roywant | 2:fc105f4c854e | 56 | |
roywant | 2:fc105f4c854e | 57 | |
simon | 0:fb6bbc10ffa0 | 58 | } |