older library
Dependencies: mbed DigitDisplay
Revision 1:e0b028efe6db, committed 2020-09-26
- Comitter:
- DavidElmoRoss
- Date:
- Sat Sep 26 20:58:40 2020 +0000
- Parent:
- 0:20e070e8ecca
- Commit message:
- older library;
Changed in this revision
diff -r 20e070e8ecca -r e0b028efe6db DigitDisplay.lib --- a/DigitDisplay.lib Sat Feb 08 05:56:25 2014 +0000 +++ b/DigitDisplay.lib Sat Sep 26 20:58:40 2020 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/seeed/code/DigitDisplay/#d3173c8bfd48 +https://os.mbed.com/users/pruek/code/DigitDisplay/#b593c32bb21f
diff -r 20e070e8ecca -r e0b028efe6db main.cpp --- a/main.cpp Sat Feb 08 05:56:25 2014 +0000 +++ b/main.cpp Sat Sep 26 20:58:40 2020 +0000 @@ -1,54 +1,61 @@ -#include "mbed.h" -#include "DigitDisplay.h" - -DigitalOut myled(LED1); - -DigitDisplay display(P1_14, P1_13); +/* + Title: Program to keep track of time on 4 digit display + Description: This program will keep keep track of time + with initial hours minutes seconds set by + Global variables. The time is given in military format +*/ +#include "mbed.h" // include mbed library +#include "DigitDisplay.h" // include digit display library +DigitalOut myled(LED1); // define myled to be internal RED led +DigitDisplay display(D2,D3); // connect digit display to D1 connector +Ticker tick; // set up periodic interrupt called tick -Ticker tick; +// Global Variables // initialize hour minute and second +uint8_t hour = 14; // same as unsigned char hour +uint8_t minute = 44; // same as unsigned char minute +uint8_t second = 0; // same as unsigned char second -uint8_t hour = 20; -uint8_t minute = 14; -uint8_t second = 0; - -void beat() +void beat() // periodic interrupt code { - static uint8_t colon = 0; - - display.setColon(colon); - if (colon) { - second++; - if (second >= 60) { - second = 0; - minute++; - if (minute >= 60) { - minute = 0; - - hour++; - if (hour >= 24) { - hour = 0; - } + static uint8_t colon = 0; // initialize colon to off + display.setColon(colon); // update colon on display + if (colon) + { // if colon on add 1 to second + second++; + if (second >= 60) + { // if > or = 60 sec reset to 0 + second = 0; + minute++; // add 1 to minute counter + if (minute >= 60) + { // if > or = 60 then reset to 0 + minute = 0; + hour++; // add 1 to hour counter + if (hour >= 24) // if > or = 24 then reset to 0 + hour = 0; + // update hour on left 2 displays display.write(0, hour / 10); display.write(1, hour % 10); - } - display.write(2, minute / 10); - display.write(3, minute % 10); - } + } // update minute on right 2 displays + display.write(2, minute / 10); + display.write(3, minute % 10); + } } - colon = 1 - colon; + colon = 1 - colon; // invert colon value } -int main() { - display.write(0, hour / 10); - display.write(1, hour % 10); - display.write(2, minute / 10); - display.write(3, minute % 10); - display.setColon(true); - tick.attach(&beat, 0.5); - while(1) { - myled = 1; - wait(0.5); - myled = 0; - wait(0.5); +int main() +{ + display.write(0, hour / 10); // put left digit of hour on left disp + display.write(1, hour % 10); // put right digit of hour on next disp + display.write(2, minute / 10); // put left digit of min on next disp + display.write(3, minute % 10); // put right digit of min on next disp + display.setColon(true); // turn colon on + tick.attach(&beat, 0.5); // beat() activates every 0.5 seconds + while(1) // endless loop + { + myled = 1; // turn off red led + wait(0.5); // wait 0.5 seconds + myled = 0; // turn on red led + wait(0.5); // wait 0.5 seconds } }
diff -r 20e070e8ecca -r e0b028efe6db mbed.bld --- a/mbed.bld Sat Feb 08 05:56:25 2014 +0000 +++ b/mbed.bld Sat Sep 26 20:58:40 2020 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file