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

Committer:
CSTritt
Date:
Thu Oct 21 10:16:51 2021 +0000
Revision:
116:a08f67e4d8e1
Parent:
115:f22cbbc92bae
Added explicit Serial port, pc.

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 116:a08f67e4d8e1 15 Serial pc(USBTX, NC, 9600);
CSTritt 116:a08f67e4d8e1 16
CSTritt 114:1cfad1babb55 17 int main()
CSTritt 114:1cfad1babb55 18 {
CSTritt 114:1cfad1babb55 19 const int DELAY = 2000000;; // mS wait time.
CSTritt 114:1cfad1babb55 20 const char ESC = 27; // Define escape character for escape sequence.
CSTritt 116:a08f67e4d8e1 21 pc.printf("%c[2J%c[H", ESC, ESC); // ANSI/VT100 clear screen/home.
CSTritt 111:956b1c606b66 22
CSTritt 115:f22cbbc92bae 23 // Replace the code below with your code.
CSTritt 116:a08f67e4d8e1 24 int count = 1; // Do while loop counter.
CSTritt 116:a08f67e4d8e1 25 int iCount = 0; // Counter in do-while loop.
CSTritt 115:f22cbbc92bae 26 do {
CSTritt 115:f22cbbc92bae 27 --iCount; // this applies to inner count.
CSTritt 115:f22cbbc92bae 28 printf("Count Down = %d and abs(Count Down) = %d\n",
CSTritt 115:f22cbbc92bae 29 iCount, abs(iCount));
CSTritt 115:f22cbbc92bae 30 } while( ++count <= 5); // This works with outer count.
CSTritt 111:956b1c606b66 31
CSTritt 116:a08f67e4d8e1 32 pc.printf("count = %d\n", count);
CSTritt 114:1cfad1babb55 33
CSTritt 114:1cfad1babb55 34 while(true) { // Main forever loop.
CSTritt 113:cc5beacdad5a 35 ThisThread::sleep_for(DELAY); // Pause
CSTritt 108:eee3167b25b4 36 }
CSTritt 113:cc5beacdad5a 37 }