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 #include "mbed.h" 00002 00003 //LEDs to indicate key presses 00004 DigitalOut myled1(LED1); 00005 DigitalOut myled2(LED2); 00006 DigitalOut myled3(LED3); 00007 00008 //init serial trx throught USB 00009 Serial pc(USBTX, USBRX); 00010 00011 //init 1 sec timer 00012 Ticker secs; 00013 00014 //variables 00015 char x,y,z,t,u,min = 0,sec = 0,hr = 0; 00016 00017 //mytick give a second of delay and print the time out. 00018 void mytick() { 00019 sec++; 00020 if (sec >= 59) { 00021 sec = 0; 00022 min ++; 00023 if (min >= 59) { 00024 min = 0; 00025 hr ++; 00026 if (hr >= 23) { 00027 hr = 0; 00028 } 00029 } 00030 } 00031 pc.printf(" %d:%d:%d \r",hr,min,sec); 00032 } 00033 00034 //software entry point 00035 void main(void){ 00036 //print general details 00037 pc.printf("hour up/down = q/a\n\r"); 00038 pc.printf("minute up/down = w/s\n\r"); 00039 pc.printf("second up/down = e/d\r\n\n\n"); 00040 //activate the timer 00041 secs.attach(&mytick,1); 00042 00043 //do forever 00044 while (1) { 00045 00046 myled1 = 0; 00047 myled2 = 0; 00048 myled3 = 0; 00049 //if any key is pressed, enter this portion of code 00050 if (pc.readable() == 1) { 00051 //get the character 00052 char ch = pc.getc(); 00053 switch (ch) { 00054 case 'q': 00055 if (hr >= 23) 00056 hr =0; 00057 myled1 = 1; 00058 hr++; 00059 pc.printf(" %d:%d:%d \r",hr,min,sec); 00060 break; 00061 case 'a': 00062 if (hr >= 23) 00063 hr =0; 00064 myled1 = 1; 00065 hr--; 00066 pc.printf(" %d:%d:%d \r",hr,min,sec); 00067 break; 00068 case 'w': 00069 if (min >= 59) 00070 min =0; 00071 myled2 = 1; 00072 min++; 00073 pc.printf(" %d:%d:%d \r",hr,min,sec); 00074 break; 00075 case 's': 00076 if (min >= 59) 00077 min =0; 00078 myled2 = 1; 00079 min--; 00080 pc.printf(" %d:%d:%d \r",hr,min,sec); 00081 break; 00082 case 'e': 00083 if (sec >= 59) 00084 sec =0; 00085 myled3 = 1; 00086 sec++; 00087 pc.printf(" %d:%d:%d \r",hr,min,sec); 00088 break; 00089 case 'd': 00090 if (sec >= 59) 00091 sec =0; 00092 myled3 = 1; 00093 sec--; 00094 pc.printf(" %d:%d:%d \r",hr,min,sec); 00095 break; 00096 } 00097 } 00098 } 00099 }
Generated on Thu Jul 28 2022 03:25:01 by
1.7.2