Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 103:decc5a1b2e80, committed 2019-11-05
- Comitter:
- reedas
- Date:
- Tue Nov 05 09:54:32 2019 +0000
- Parent:
- 102:17e6fc7c4be0
- Commit message:
- updated with conditional blinking
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Nov 05 09:15:05 2019 +0000 +++ b/main.cpp Tue Nov 05 09:54:32 2019 +0000 @@ -12,8 +12,9 @@ DigitalOut BlueLED(LED3); DigitalOut led1(LED4); DigitalOut led2(LED5); +DigitalIn sw2(P0_4); -#define SLEEP_TIME 500 // (msec) +#define SLEEP_TIME 200 // (msec) #define PRINT_AFTER_N_LOOPS 20 // main() runs in its own thread in the OS @@ -24,12 +25,20 @@ int count = 0; while (true) { // Blink LED and wait 0.5 seconds - led1 = !led1; - led2 = !led2; - RedLED = !RedLED; - GreenLED = !GreenLED; - BlueLED = !BlueLED; - thread_sleep_for(SLEEP_TIME); + if (sw2 == 1) { + led1= !led1; + thread_sleep_for(SLEEP_TIME); + led2 = !led2; + } + else { + thread_sleep_for(SLEEP_TIME); + RedLED = !RedLED; + thread_sleep_for(SLEEP_TIME); + GreenLED = !GreenLED; + thread_sleep_for(SLEEP_TIME); + BlueLED = !BlueLED; + thread_sleep_for(SLEEP_TIME); + } if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { // Following the main thread wait, report on the current system status