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.
Dependencies: mbed DigitDisplay
main.cpp
00001 /* 00002 Title: Program to keep track of time on 4 digit display 00003 Description: This program will keep keep track of time 00004 with initial hours minutes seconds set by 00005 Global variables. The time is given in military format 00006 */ 00007 #include "mbed.h" // include mbed library 00008 #include "DigitDisplay.h" // include digit display library 00009 DigitalOut myled(LED1); // define myled to be internal RED led 00010 DigitDisplay display(D2,D3); // connect digit display to D1 connector 00011 Ticker tick; // set up periodic interrupt called tick 00012 00013 // Global Variables // initialize hour minute and second 00014 uint8_t hour = 14; // same as unsigned char hour 00015 uint8_t minute = 44; // same as unsigned char minute 00016 uint8_t second = 0; // same as unsigned char second 00017 00018 void beat() // periodic interrupt code 00019 { 00020 static uint8_t colon = 0; // initialize colon to off 00021 display.setColon(colon); // update colon on display 00022 if (colon) 00023 { // if colon on add 1 to second 00024 second++; 00025 if (second >= 60) 00026 { // if > or = 60 sec reset to 0 00027 second = 0; 00028 minute++; // add 1 to minute counter 00029 if (minute >= 60) 00030 { // if > or = 60 then reset to 0 00031 minute = 0; 00032 hour++; // add 1 to hour counter 00033 if (hour >= 24) // if > or = 24 then reset to 0 00034 hour = 0; 00035 // update hour on left 2 displays 00036 display.write(0, hour / 10); 00037 display.write(1, hour % 10); 00038 } // update minute on right 2 displays 00039 display.write(2, minute / 10); 00040 display.write(3, minute % 10); 00041 } 00042 } 00043 colon = 1 - colon; // invert colon value 00044 } 00045 00046 int main() 00047 { 00048 display.write(0, hour / 10); // put left digit of hour on left disp 00049 display.write(1, hour % 10); // put right digit of hour on next disp 00050 display.write(2, minute / 10); // put left digit of min on next disp 00051 display.write(3, minute % 10); // put right digit of min on next disp 00052 display.setColon(true); // turn colon on 00053 tick.attach(&beat, 0.5); // beat() activates every 0.5 seconds 00054 while(1) // endless loop 00055 { 00056 myled = 1; // turn off red led 00057 wait(0.5); // wait 0.5 seconds 00058 myled = 0; // turn on red led 00059 wait(0.5); // wait 0.5 seconds 00060 } 00061 }
Generated on Wed Jul 20 2022 14:05:14 by
1.7.2