Charles Tritt
/
21_SerialPass_v5
New example. Initial version.
Diff: main.cpp
- Revision:
- 115:6ba84689e2c9
- Parent:
- 114:1cfad1babb55
- Child:
- 116:8990686eedf5
diff -r 1cfad1babb55 -r 6ba84689e2c9 main.cpp --- a/main.cpp Tue Oct 12 21:48:12 2021 +0000 +++ b/main.cpp Wed Oct 13 13:08:42 2021 +0000 @@ -1,36 +1,36 @@ /* -Project: 21_ScopeEx1_v5 +Project: 21_TimeSense_v5 File: main.cpp - This simple program demonstrates that C passes arguments by value. + A simple time sense game. Uses VT-100 escape sequences to prevent scrolling. See http://www.csie.ntu.edu.tw/~r92094/c++/VT100.html and/or https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797. - Written by: Dr. C. S. Tritt; Last revised 10/11/21 (v. 1.1) + Written by: Dr. C. S. Tritt; Last revised 10/13/21 (v. 1.1) */ #include "mbed.h" +#include "myFuncs.h" +// Construct a USER_BUTTON digital input. +DigitalIn myButton(USER_BUTTON); + // Construct a timer object. +Timer myTimer; + // Construct a transmit only serial connection over our USB. +Serial pc(USBTX, NC, 9600); int main() { - const int DELAY = 2000000;; // mS wait time. - const char ESC = 27; // Define escape character for escape sequence. - printf("%c[2J%c[H", ESC, ESC); // ANSI/VT100 clear screen/home. - - int count1 = 1; // Declared in outer block + const int TARGET = 5000; // Target time in mS. + const int TRIALS = 3; // Number of trials (cycles). + int rSum = 0; // Running sum for average in mS. - do { // Do while construct may be new to you! - int count2 = 0; // Declared & initialized in inner block - ++count2; // Ineffective due to line above! - printf("count1 = %d count2 = %d\n", count1, count2); - // Note that count1 is incremented in while test! - } while (++count1 <= 5); // count2 no longer exists after loop exit. + clrTerm(&pc); // Clear the terminal. + pc.printf("Hold button down for %f seconds.\n", + static_cast<float>(TARGET)/1000.f); - printf("count1 = %d\n", count1); - return 0; while(true) { // Main forever loop. - ThisThread::sleep_for(DELAY); // Pause + ThisThread::sleep_for(300000); // Sleep for 5 minutes, repeatedly. } } \ No newline at end of file