Charles Tritt
/
21_ButtonTests_v5
Initial published version.
Revision 110:8170476d91a6, committed 2021-09-24
- Comitter:
- CSTritt
- Date:
- Fri Sep 24 16:28:15 2021 +0000
- Parent:
- 109:744c6cb711bf
- Commit message:
- Changed comment regarding %b format.; ; Changed message after inner while loop.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 744c6cb711bf -r 8170476d91a6 main.cpp --- a/main.cpp Thu Sep 23 03:03:59 2021 +0000 +++ b/main.cpp Fri Sep 24 16:28:15 2021 +0000 @@ -16,12 +16,14 @@ // not good practice, but I want to use the DigitalIn object in these // contexts to illustrate my points. See while loop below for a better // (more common and realistic) approach. - while(true) { + //while(true) { // Standard infinite loop. + for (;;) { // Alternative infinite loop. // Use the button in some printf calls. printf("\nuB (w/o cast) = %d.\n", uB); // Bad! Warning! Wrong! printf("uB (with int cast) = %d.\n", static_cast<int>(uB)); // I found a reference that claimed there is a %b (or B) speicifer for - // type bool, but it doesn't work in mbed. + // type bool, but it doesn't work in mbed. So use %d to see it as a + // decimal value. printf("uB (with bool cast) = %d.\n", static_cast<bool>(uB)); printf("uB.read = %d.\n", uB.read()); @@ -62,6 +64,9 @@ } //end of if. ThisThread::sleep_for(500); // For 0.5 seconds in while. } // end of !uBstate while. - printf("End of main while.\n\n"); + if (uBstate) + printf("Button released during countdown.\n\n"); + else + printf("Countdown completed.\n\n"); } // end of main while. } // end of main function. \ No newline at end of file