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.
Dependencies: mbed
main.cpp@0:580af977fe72, 2019-10-08 (annotated)
- Committer:
- loicb2000
- Date:
- Tue Oct 08 16:42:37 2019 +0000
- Revision:
- 0:580af977fe72
Exercise 1a
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| loicb2000 | 0:580af977fe72 | 1 | |
| loicb2000 | 0:580af977fe72 | 2 | #include "mbed.h" |
| loicb2000 | 0:580af977fe72 | 3 | |
| loicb2000 | 0:580af977fe72 | 4 | DigitalOut myled(LED1); // use onboard LED #1 |
| loicb2000 | 0:580af977fe72 | 5 | |
| loicb2000 | 0:580af977fe72 | 6 | int main() { |
| loicb2000 | 0:580af977fe72 | 7 | |
| loicb2000 | 0:580af977fe72 | 8 | int mycounter; |
| loicb2000 | 0:580af977fe72 | 9 | int flashtimes; |
| loicb2000 | 0:580af977fe72 | 10 | |
| loicb2000 | 0:580af977fe72 | 11 | while(1) { // repeat the program indefinitely |
| loicb2000 | 0:580af977fe72 | 12 | for(flashtimes=0;flashtimes<5;flashtimes++) { // repeat five times |
| loicb2000 | 0:580af977fe72 | 13 | for(mycounter=0;mycounter<=flashtimes;mycounter++) { // repeat 'flashtimes' number |
| loicb2000 | 0:580af977fe72 | 14 | myled = 1; // turn on LED #1 |
| loicb2000 | 0:580af977fe72 | 15 | wait(0.250); // 250ms 'on' time |
| loicb2000 | 0:580af977fe72 | 16 | myled = 0; // turn off LED #1 |
| loicb2000 | 0:580af977fe72 | 17 | wait(0.250); // 250ms 'off' time |
| loicb2000 | 0:580af977fe72 | 18 | } |
| loicb2000 | 0:580af977fe72 | 19 | wait(1.000); // 1s pause |
| loicb2000 | 0:580af977fe72 | 20 | } |
| loicb2000 | 0:580af977fe72 | 21 | |
| loicb2000 | 0:580af977fe72 | 22 | for(flashtimes=5;flashtimes>0;flashtimes--) { // repeat five times |
| loicb2000 | 0:580af977fe72 | 23 | for(mycounter=0;mycounter<flashtimes;mycounter++) { // repeat 'flashtimes' number |
| loicb2000 | 0:580af977fe72 | 24 | myled = 1; // turn on LED #1 |
| loicb2000 | 0:580af977fe72 | 25 | wait(0.250); // 250ms 'on' time |
| loicb2000 | 0:580af977fe72 | 26 | myled = 0; // turn off LED #1 |
| loicb2000 | 0:580af977fe72 | 27 | wait(0.250); // 250ms 'off' time |
| loicb2000 | 0:580af977fe72 | 28 | } |
| loicb2000 | 0:580af977fe72 | 29 | wait(1.000); // 1s pause |
| loicb2000 | 0:580af977fe72 | 30 | } |
| loicb2000 | 0:580af977fe72 | 31 | } |
| loicb2000 | 0:580af977fe72 | 32 | } |
| loicb2000 | 0:580af977fe72 | 33 | |
| loicb2000 | 0:580af977fe72 | 34 |