Use this project as a starting point for simple IO testing in Mbed. This is the initial version.

Committer:
CSTritt
Date:
Wed Oct 13 14:27:35 2021 +0000
Revision:
115:f22cbbc92bae
Parent:
114:1cfad1babb55
Child:
116:a08f67e4d8e1
Use this project as a starting point for simple console IO testing in Mbed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CSTritt 107:61b9c99a4e27 1 /*
CSTritt 115:f22cbbc92bae 2 Project: 21_ConsoleIO_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:f22cbbc92bae 21 // Replace the code below with your code.
CSTritt 115:f22cbbc92bae 22 int count = 1; // Declared in outer block.
CSTritt 115:f22cbbc92bae 23 int iCount = 0; // This is another variable called count.
CSTritt 115:f22cbbc92bae 24 do {
CSTritt 115:f22cbbc92bae 25 --iCount; // this applies to inner count.
CSTritt 115:f22cbbc92bae 26 printf("Count Down = %d and abs(Count Down) = %d\n",
CSTritt 115:f22cbbc92bae 27 iCount, abs(iCount));
CSTritt 115:f22cbbc92bae 28 } while( ++count <= 5); // This works with outer count.
CSTritt 111:956b1c606b66 29
CSTritt 115:f22cbbc92bae 30 printf("count = %d\n", count); // Inner count is dead.
CSTritt 114:1cfad1babb55 31
CSTritt 114:1cfad1babb55 32 while(true) { // Main forever loop.
CSTritt 113:cc5beacdad5a 33 ThisThread::sleep_for(DELAY); // Pause
CSTritt 108:eee3167b25b4 34 }
CSTritt 113:cc5beacdad5a 35 }