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.
Fork of Task322Solution by
main.cpp@0:363a62c6c97c, 2015-09-24 (annotated)
- Committer:
- noutram
- Date:
- Thu Sep 24 12:25:31 2015 +0000
- Revision:
- 0:363a62c6c97c
Initial version 24-09-2015
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| noutram | 0:363a62c6c97c | 1 | #include "mbed.h" |
| noutram | 0:363a62c6c97c | 2 | |
| noutram | 0:363a62c6c97c | 3 | DigitalOut red_led(D7); |
| noutram | 0:363a62c6c97c | 4 | DigitalOut yellow_led(D6); |
| noutram | 0:363a62c6c97c | 5 | DigitalOut green_led(D5); |
| noutram | 0:363a62c6c97c | 6 | DigitalIn SW1(D4); |
| noutram | 0:363a62c6c97c | 7 | |
| noutram | 0:363a62c6c97c | 8 | //This is the solution based on the proposed flowchart. |
| noutram | 0:363a62c6c97c | 9 | //It is flawed however (see next exercise) due to |
| noutram | 0:363a62c6c97c | 10 | //switch bounce. |
| noutram | 0:363a62c6c97c | 11 | |
| noutram | 0:363a62c6c97c | 12 | int main() { |
| noutram | 0:363a62c6c97c | 13 | |
| noutram | 0:363a62c6c97c | 14 | //Switch on Yellow and Green to indicate |
| noutram | 0:363a62c6c97c | 15 | //that the code is running |
| noutram | 0:363a62c6c97c | 16 | yellow_led = 1; |
| noutram | 0:363a62c6c97c | 17 | green_led = 1; |
| noutram | 0:363a62c6c97c | 18 | red_led = 0; //Set RED LED to OFF |
| noutram | 0:363a62c6c97c | 19 | |
| noutram | 0:363a62c6c97c | 20 | // Wait for SW1 to be pressed |
| noutram | 0:363a62c6c97c | 21 | while (SW1 == 0) { } |
| noutram | 0:363a62c6c97c | 22 | |
| noutram | 0:363a62c6c97c | 23 | // Wait for SW1 to be released |
| noutram | 0:363a62c6c97c | 24 | while (SW1 == 1) { } |
| noutram | 0:363a62c6c97c | 25 | |
| noutram | 0:363a62c6c97c | 26 | red_led = 1; //Turn ON LED |
| noutram | 0:363a62c6c97c | 27 | |
| noutram | 0:363a62c6c97c | 28 | while (1) { } //Repeat forever |
| noutram | 0:363a62c6c97c | 29 | } |
