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
00001 /* Program Example 9.5: Tests Timer duration, displaying current time values to terminal 00002 */ 00003 #include "mbed.h" 00004 00005 Timer t; 00006 float s=0; //seconds cumulative count 00007 float m=0; //minutes cumulative count 00008 DigitalOut diag (LED1); 00009 Serial pc(USBTX, USBRX); 00010 00011 int main() { 00012 pc.printf("\r\nTimer Duration Test\n\r"); 00013 pc.printf("-------------------\n\n\r"); 00014 t.reset(); //reset Timer 00015 t.start(); // start Timer 00016 while(1){ 00017 if (t.read()>=(s+1)){ //has Timer passed next whole second? 00018 diag = 1; //If yes, flash LED and print a message 00019 wait (0.05); 00020 diag = 0; 00021 s++ ; 00022 //print the number of seconds exceeding whole minutes 00023 pc.printf("%1.0f seconds\r\n",(s-60*(m-1))); 00024 } 00025 if (t.read()>=60*m){ 00026 printf("%1.0f minutes \n\r",m); 00027 m++ ; 00028 } 00029 if (t.read()<s){ //test for overflow 00030 pc.printf("\r\nTimer has overflowed!\n\r"); 00031 for(;;){} //lock into an endless loop doing nothing 00032 } 00033 } //end of while 00034 } 00035
Generated on Tue Jul 26 2022 01:34:29 by
1.7.2