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.
main.cpp@115:8bd6e72f6e28, 2021-10-13 (annotated)
- Committer:
- CSTritt
- Date:
- Wed Oct 13 15:51:01 2021 +0000
- Revision:
- 115:8bd6e72f6e28
- Parent:
- 114:1cfad1babb55
First v5 version. Note how twisted this is. Outer count is incremented in while test expression.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 107:61b9c99a4e27 | 1 | /* |
CSTritt | 115:8bd6e72f6e28 | 2 | Project: 21_ScopeEx2_v5 |
CSTritt | 109:b061f9830736 | 3 | File: main.cpp |
CSTritt | 111:956b1c606b66 | 4 | |
CSTritt | 111:956b1c606b66 | 5 | This simple program demonstrates that C passes arguments by value. |
CSTritt | 114:1cfad1babb55 | 6 | |
CSTritt | 114:1cfad1babb55 | 7 | Uses VT-100 escape sequences to prevent scrolling. See |
CSTritt | 114:1cfad1babb55 | 8 | http://www.csie.ntu.edu.tw/~r92094/c++/VT100.html and/or |
CSTritt | 113:cc5beacdad5a | 9 | https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797. |
CSTritt | 114:1cfad1babb55 | 10 | |
CSTritt | 113:cc5beacdad5a | 11 | Written by: Dr. C. S. Tritt; Last revised 10/11/21 (v. 1.1) |
CSTritt | 107:61b9c99a4e27 | 12 | */ |
Jonathan Austin |
0:2757d7abb7d9 | 13 | #include "mbed.h" |
CSTritt | 108:eee3167b25b4 | 14 | |
CSTritt | 114:1cfad1babb55 | 15 | int main() |
CSTritt | 114:1cfad1babb55 | 16 | { |
CSTritt | 114:1cfad1babb55 | 17 | const int DELAY = 2000000;; // mS wait time. |
CSTritt | 114:1cfad1babb55 | 18 | const char ESC = 27; // Define escape character for escape sequence. |
CSTritt | 114:1cfad1babb55 | 19 | printf("%c[2J%c[H", ESC, ESC); // ANSI/VT100 clear screen/home. |
CSTritt | 111:956b1c606b66 | 20 | |
CSTritt | 115:8bd6e72f6e28 | 21 | int count = 0; // Declared in outer block. |
CSTritt | 115:8bd6e72f6e28 | 22 | do { |
CSTritt | 115:8bd6e72f6e28 | 23 | int count = 0; // This is another variable called count. |
CSTritt | 115:8bd6e72f6e28 | 24 | ++count; // this applies to inner count. |
CSTritt | 115:8bd6e72f6e28 | 25 | printf("count = %d\n", count); |
CSTritt | 115:8bd6e72f6e28 | 26 | } while( ++count <= 5); // This works with outer count. |
CSTritt | 111:956b1c606b66 | 27 | |
CSTritt | 115:8bd6e72f6e28 | 28 | printf("count = %d\n", count); // Inner count is dead. |
CSTritt | 114:1cfad1babb55 | 29 | |
CSTritt | 114:1cfad1babb55 | 30 | while(true) { // Main forever loop. |
CSTritt | 113:cc5beacdad5a | 31 | ThisThread::sleep_for(DELAY); // Pause |
CSTritt | 108:eee3167b25b4 | 32 | } |
CSTritt | 113:cc5beacdad5a | 33 | } |