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 Task132Solution by
main.cpp@2:bc188ffd11f8, 2019-09-10 (annotated)
- Committer:
- noutram
- Date:
- Tue Sep 10 14:32:04 2019 +0000
- Revision:
- 2:bc188ffd11f8
- Parent:
- 0:8c84f2a81909
2019
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| noutram | 0:8c84f2a81909 | 1 | //This is known as a “header file” |
| noutram | 0:8c84f2a81909 | 2 | //In short, this copies and pastes the text file |
| noutram | 0:8c84f2a81909 | 3 | //mbed.h into this code |
| noutram | 0:8c84f2a81909 | 4 | #include "mbed.h" |
| noutram | 0:8c84f2a81909 | 5 | |
| noutram | 0:8c84f2a81909 | 6 | //Create a DigitalOut “object” called myled |
| noutram | 0:8c84f2a81909 | 7 | //Pass constant D7 as a “parameter” |
| noutram | 0:8c84f2a81909 | 8 | DigitalOut redLED(D7); |
| noutram | 0:8c84f2a81909 | 9 | DigitalOut yellowLED(D6); |
| noutram | 0:8c84f2a81909 | 10 | DigitalOut greenLED(D5); |
| noutram | 0:8c84f2a81909 | 11 | |
| noutram | 0:8c84f2a81909 | 12 | //The main function - all executable C / C++ |
| noutram | 0:8c84f2a81909 | 13 | //applications have a main function. This is |
| noutram | 0:8c84f2a81909 | 14 | //out entry point in the software |
| noutram | 0:8c84f2a81909 | 15 | int main() { |
| noutram | 0:8c84f2a81909 | 16 | |
| noutram | 0:8c84f2a81909 | 17 | redLED = 0; |
| noutram | 0:8c84f2a81909 | 18 | yellowLED = 0; |
| noutram | 0:8c84f2a81909 | 19 | greenLED = 0; |
| noutram | 0:8c84f2a81909 | 20 | |
| noutram | 0:8c84f2a81909 | 21 | // ALL the code is contained in a |
| noutram | 0:8c84f2a81909 | 22 | // “while loop" |
| noutram | 0:8c84f2a81909 | 23 | |
| noutram | 0:8c84f2a81909 | 24 | |
| noutram | 0:8c84f2a81909 | 25 | while(1) |
| noutram | 0:8c84f2a81909 | 26 | { |
| noutram | 0:8c84f2a81909 | 27 | //The code between the { curly braces } |
| noutram | 0:8c84f2a81909 | 28 | //is the code that is repeated |
| noutram | 0:8c84f2a81909 | 29 | |
| noutram | 0:8c84f2a81909 | 30 | //STATE 1 (R) |
| noutram | 0:8c84f2a81909 | 31 | redLED = 1; |
| noutram | 0:8c84f2a81909 | 32 | yellowLED = 0; |
| noutram | 0:8c84f2a81909 | 33 | greenLED = 0; |
| noutram | 0:8c84f2a81909 | 34 | wait(1.0); |
| noutram | 0:8c84f2a81909 | 35 | |
| noutram | 0:8c84f2a81909 | 36 | //STATE 2 (RA) |
| noutram | 0:8c84f2a81909 | 37 | yellowLED = 1; |
| noutram | 0:8c84f2a81909 | 38 | wait(1.0); |
| noutram | 0:8c84f2a81909 | 39 | |
| noutram | 0:8c84f2a81909 | 40 | //STATE 3 (G) |
| noutram | 0:8c84f2a81909 | 41 | redLED = 0; |
| noutram | 0:8c84f2a81909 | 42 | yellowLED = 0; |
| noutram | 0:8c84f2a81909 | 43 | greenLED = 1; |
| noutram | 0:8c84f2a81909 | 44 | wait(1.0); |
| noutram | 0:8c84f2a81909 | 45 | |
| noutram | 0:8c84f2a81909 | 46 | //STATE 4 (A) |
| noutram | 0:8c84f2a81909 | 47 | yellowLED = 1; |
| noutram | 0:8c84f2a81909 | 48 | greenLED = 0; |
| noutram | 0:8c84f2a81909 | 49 | wait(1.0); |
| noutram | 0:8c84f2a81909 | 50 | } |
| noutram | 0:8c84f2a81909 | 51 | } |
