Andrew Reed
/
mbed-os-example-blinky3_working
CITY1082 code example
main.cpp@103:decc5a1b2e80, 2019-11-05 (annotated)
- Committer:
- reedas
- Date:
- Tue Nov 05 09:54:32 2019 +0000
- Revision:
- 103:decc5a1b2e80
- Parent:
- 102:17e6fc7c4be0
updated with conditional blinking
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 82:abf1b1785bd7 | 1 | /* mbed Microcontroller Library |
mbed_official | 82:abf1b1785bd7 | 2 | * Copyright (c) 2018 ARM Limited |
mbed_official | 82:abf1b1785bd7 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbed_official | 82:abf1b1785bd7 | 4 | */ |
mbed_official | 82:abf1b1785bd7 | 5 | |
Jonathan Austin |
0:2757d7abb7d9 | 6 | #include "mbed.h" |
mbed_official | 100:ec006d6f3cb6 | 7 | #include "platform/mbed_thread.h" |
mbed_official | 82:abf1b1785bd7 | 8 | #include "stats_report.h" |
Jonathan Austin |
0:2757d7abb7d9 | 9 | |
reedas | 102:17e6fc7c4be0 | 10 | DigitalOut RedLED(LED1); |
reedas | 102:17e6fc7c4be0 | 11 | DigitalOut GreenLED(LED2); |
reedas | 102:17e6fc7c4be0 | 12 | DigitalOut BlueLED(LED3); |
reedas | 102:17e6fc7c4be0 | 13 | DigitalOut led1(LED4); |
reedas | 102:17e6fc7c4be0 | 14 | DigitalOut led2(LED5); |
reedas | 103:decc5a1b2e80 | 15 | DigitalIn sw2(P0_4); |
Jonathan Austin |
0:2757d7abb7d9 | 16 | |
reedas | 103:decc5a1b2e80 | 17 | #define SLEEP_TIME 200 // (msec) |
mbed_official | 88:bea4f2daa48c | 18 | #define PRINT_AFTER_N_LOOPS 20 |
mbed_official | 88:bea4f2daa48c | 19 | |
Jonathan Austin |
1:846c97078558 | 20 | // main() runs in its own thread in the OS |
mbed_official | 82:abf1b1785bd7 | 21 | int main() |
mbed_official | 82:abf1b1785bd7 | 22 | { |
mbed_official | 88:bea4f2daa48c | 23 | SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); |
mbed_official | 82:abf1b1785bd7 | 24 | |
mbed_official | 88:bea4f2daa48c | 25 | int count = 0; |
Jonathan Austin |
0:2757d7abb7d9 | 26 | while (true) { |
mbed_official | 82:abf1b1785bd7 | 27 | // Blink LED and wait 0.5 seconds |
reedas | 103:decc5a1b2e80 | 28 | if (sw2 == 1) { |
reedas | 103:decc5a1b2e80 | 29 | led1= !led1; |
reedas | 103:decc5a1b2e80 | 30 | thread_sleep_for(SLEEP_TIME); |
reedas | 103:decc5a1b2e80 | 31 | led2 = !led2; |
reedas | 103:decc5a1b2e80 | 32 | } |
reedas | 103:decc5a1b2e80 | 33 | else { |
reedas | 103:decc5a1b2e80 | 34 | thread_sleep_for(SLEEP_TIME); |
reedas | 103:decc5a1b2e80 | 35 | RedLED = !RedLED; |
reedas | 103:decc5a1b2e80 | 36 | thread_sleep_for(SLEEP_TIME); |
reedas | 103:decc5a1b2e80 | 37 | GreenLED = !GreenLED; |
reedas | 103:decc5a1b2e80 | 38 | thread_sleep_for(SLEEP_TIME); |
reedas | 103:decc5a1b2e80 | 39 | BlueLED = !BlueLED; |
reedas | 103:decc5a1b2e80 | 40 | thread_sleep_for(SLEEP_TIME); |
reedas | 103:decc5a1b2e80 | 41 | } |
mbed_official | 82:abf1b1785bd7 | 42 | |
mbed_official | 88:bea4f2daa48c | 43 | if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { |
mbed_official | 88:bea4f2daa48c | 44 | // Following the main thread wait, report on the current system status |
mbed_official | 88:bea4f2daa48c | 45 | sys_state.report_state(); |
mbed_official | 88:bea4f2daa48c | 46 | count = 0; |
mbed_official | 88:bea4f2daa48c | 47 | } |
mbed_official | 88:bea4f2daa48c | 48 | ++count; |
Jonathan Austin |
0:2757d7abb7d9 | 49 | } |
Jonathan Austin |
0:2757d7abb7d9 | 50 | } |