First step in making the code to be more independent on each board. This version is just for TinyBLE, the next will be a bit more generic
Dependencies: BLE_API mbed nRF51822
Fork of EddystoneBeaconSwitchLed by
main.cpp@3:2340e6920afe, 2015-09-29 (annotated)
- Committer:
- scottjenson
- Date:
- Tue Sep 29 00:22:55 2015 +0000
- Revision:
- 3:2340e6920afe
- Parent:
- 2:fc105f4c854e
Update for tinyBLE
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 | |
scottjenson | 3:2340e6920afe | 5 | int ledOn = 0; |
scottjenson | 3:2340e6920afe | 6 | int ledOff = 1; |
roywant | 2:fc105f4c854e | 7 | |
roywant | 2:fc105f4c854e | 8 | InterruptIn button1(P0_17); |
roywant | 2:fc105f4c854e | 9 | InterruptIn mysw1(P0_18); |
scottjenson | 3:2340e6920afe | 10 | DigitalOut myled1(P0_21); |
scottjenson | 3:2340e6920afe | 11 | DigitalOut myled2(P0_22); |
scottjenson | 3:2340e6920afe | 12 | DigitalOut myled3(P0_23); |
roywant | 2:fc105f4c854e | 13 | // Serial pc(USBTX,USBRX); |
roywant | 2:fc105f4c854e | 14 | int flag = false; |
simon | 0:fb6bbc10ffa0 | 15 | |
scottjenson | 3:2340e6920afe | 16 | void handle_button1() { |
roywant | 2:fc105f4c854e | 17 | flag = !flag; |
roywant | 2:fc105f4c854e | 18 | } |
roywant | 2:fc105f4c854e | 19 | |
roywant | 2:fc105f4c854e | 20 | |
roywant | 2:fc105f4c854e | 21 | void ledflasher() { |
scottjenson | 3:2340e6920afe | 22 | myled1 = ledOn; |
roywant | 2:fc105f4c854e | 23 | wait(0.3); |
scottjenson | 3:2340e6920afe | 24 | myled1 = ledOff; |
scottjenson | 3:2340e6920afe | 25 | myled2 = ledOn; |
roywant | 2:fc105f4c854e | 26 | wait(0.3); |
scottjenson | 3:2340e6920afe | 27 | myled2 = ledOff; |
scottjenson | 3:2340e6920afe | 28 | myled3 = ledOn; |
roywant | 2:fc105f4c854e | 29 | wait(0.4); |
scottjenson | 3:2340e6920afe | 30 | myled3 = ledOff; |
roywant | 2:fc105f4c854e | 31 | } |
simon | 0:fb6bbc10ffa0 | 32 | |
simon | 0:fb6bbc10ffa0 | 33 | int main() { |
roywant | 2:fc105f4c854e | 34 | // Initialize button1 and pull up |
roywant | 2:fc105f4c854e | 35 | // set interrupt callback for button1 |
scottjenson | 3:2340e6920afe | 36 | button1.fall(&handle_button1); |
roywant | 2:fc105f4c854e | 37 | button1.mode(PullUp); |
scottjenson | 3:2340e6920afe | 38 | myled1 = ledOff; |
scottjenson | 3:2340e6920afe | 39 | myled2 = ledOff; |
scottjenson | 3:2340e6920afe | 40 | myled3 = ledOff; |
roywant | 2:fc105f4c854e | 41 | |
simon | 0:fb6bbc10ffa0 | 42 | while(1) { |
roywant | 2:fc105f4c854e | 43 | if (flag) { |
roywant | 2:fc105f4c854e | 44 | ledflasher(); |
roywant | 2:fc105f4c854e | 45 | } |
simon | 0:fb6bbc10ffa0 | 46 | wait(0.2); |
simon | 0:fb6bbc10ffa0 | 47 | } |
roywant | 2:fc105f4c854e | 48 | |
roywant | 2:fc105f4c854e | 49 | |
roywant | 2:fc105f4c854e | 50 | |
simon | 0:fb6bbc10ffa0 | 51 | } |