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: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
Time/Adafruit_Display/clock_display.cpp@25:863e6ef1245f, 2021-04-27 (annotated)
- Committer:
- ackerden
- Date:
- Tue Apr 27 20:04:51 2021 +0000
- Revision:
- 25:863e6ef1245f
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ackerden | 25:863e6ef1245f | 1 | /*#include "mbed.h" |
| ackerden | 25:863e6ef1245f | 2 | #include "Adafruit_LED_Backpack.h" |
| ackerden | 25:863e6ef1245f | 3 | #include "Adafruit_GFX.h" |
| ackerden | 25:863e6ef1245f | 4 | |
| ackerden | 25:863e6ef1245f | 5 | #include "clock_display.h" |
| ackerden | 25:863e6ef1245f | 6 | |
| ackerden | 25:863e6ef1245f | 7 | #define TIME_24_HOUR true |
| ackerden | 25:863e6ef1245f | 8 | #define DISPLAY_ADDRESS 0x70 |
| ackerden | 25:863e6ef1245f | 9 | /* |
| ackerden | 25:863e6ef1245f | 10 | Adafruit_7segment clockDisplay = Adafruit_7segment(); |
| ackerden | 25:863e6ef1245f | 11 | clockDisplay.begin(DISPLAY_ADDRESS); |
| ackerden | 25:863e6ef1245f | 12 | bool blinkColon = false; |
| ackerden | 25:863e6ef1245f | 13 | |
| ackerden | 25:863e6ef1245f | 14 | |
| ackerden | 25:863e6ef1245f | 15 | void clock_display(int seconds, int minutes, int hours){ |
| ackerden | 25:863e6ef1245f | 16 | /*if (minutes == 0) { |
| ackerden | 25:863e6ef1245f | 17 | hours = now.hour(); |
| ackerden | 25:863e6ef1245f | 18 | minutes = now.minute(); |
| ackerden | 25:863e6ef1245f | 19 | }*/ |
| ackerden | 25:863e6ef1245f | 20 | |
| ackerden | 25:863e6ef1245f | 21 | // Show the time on the display by turning it into a numeric |
| ackerden | 25:863e6ef1245f | 22 | // value, like 3:30 turns into 330, by multiplying the hour by |
| ackerden | 25:863e6ef1245f | 23 | // 100 and then adding the minutes. |
| ackerden | 25:863e6ef1245f | 24 | /* int displayValue = hours*100 + minutes; |
| ackerden | 25:863e6ef1245f | 25 | |
| ackerden | 25:863e6ef1245f | 26 | // Now print the time value to the display. |
| ackerden | 25:863e6ef1245f | 27 | clockDisplay.print(displayValue, DEC); |
| ackerden | 25:863e6ef1245f | 28 | |
| ackerden | 25:863e6ef1245f | 29 | // Add zero padding when in 24 hour mode and it's midnight. |
| ackerden | 25:863e6ef1245f | 30 | // In this case the print function above won't have leading 0's |
| ackerden | 25:863e6ef1245f | 31 | // which can look confusing. Go in and explicitly add these zeros. |
| ackerden | 25:863e6ef1245f | 32 | if (TIME_24_HOUR && hours == 0) { |
| ackerden | 25:863e6ef1245f | 33 | // Pad hour 0. |
| ackerden | 25:863e6ef1245f | 34 | clockDisplay.writeDigitNum(1, 0); |
| ackerden | 25:863e6ef1245f | 35 | // Also pad when the 10's minute is 0 and should be padded. |
| ackerden | 25:863e6ef1245f | 36 | if (minutes < 10) { |
| ackerden | 25:863e6ef1245f | 37 | clockDisplay.writeDigitNum(2, 0); |
| ackerden | 25:863e6ef1245f | 38 | } |
| ackerden | 25:863e6ef1245f | 39 | } |
| ackerden | 25:863e6ef1245f | 40 | |
| ackerden | 25:863e6ef1245f | 41 | // Blink the colon by flipping its value every loop iteration |
| ackerden | 25:863e6ef1245f | 42 | // (which happens every second). |
| ackerden | 25:863e6ef1245f | 43 | blinkColon = !blinkColon; |
| ackerden | 25:863e6ef1245f | 44 | clockDisplay.drawColon(blinkColon); |
| ackerden | 25:863e6ef1245f | 45 | |
| ackerden | 25:863e6ef1245f | 46 | // Now push out to the display the new values that were set above. |
| ackerden | 25:863e6ef1245f | 47 | clockDisplay.writeDisplay(); |
| ackerden | 25:863e6ef1245f | 48 | |
| ackerden | 25:863e6ef1245f | 49 | // Pause for a second for time to elapse. This value is in milliseconds |
| ackerden | 25:863e6ef1245f | 50 | // so 1000 milliseconds = 1 second. |
| ackerden | 25:863e6ef1245f | 51 | delay(1000); |
| ackerden | 25:863e6ef1245f | 52 | |
| ackerden | 25:863e6ef1245f | 53 | // Now increase the seconds by one. |
| ackerden | 25:863e6ef1245f | 54 | seconds += 1; |
| ackerden | 25:863e6ef1245f | 55 | // If the seconds go above 59 then the minutes should increase and |
| ackerden | 25:863e6ef1245f | 56 | // the seconds should wrap back to 0. |
| ackerden | 25:863e6ef1245f | 57 | if (seconds > 59) { |
| ackerden | 25:863e6ef1245f | 58 | seconds = 0; |
| ackerden | 25:863e6ef1245f | 59 | minutes += 1; |
| ackerden | 25:863e6ef1245f | 60 | // Again if the minutes go above 59 then the hour should increase and |
| ackerden | 25:863e6ef1245f | 61 | // the minutes should wrap back to 0. |
| ackerden | 25:863e6ef1245f | 62 | if (minutes > 59) { |
| ackerden | 25:863e6ef1245f | 63 | minutes = 0; |
| ackerden | 25:863e6ef1245f | 64 | hours += 1; |
| ackerden | 25:863e6ef1245f | 65 | // Note that when the minutes are 0 (i.e. it's the top of a new hour) |
| ackerden | 25:863e6ef1245f | 66 | // then the start of the loop will read the actual time from the DS1307 |
| ackerden | 25:863e6ef1245f | 67 | // again. Just to be safe though we'll also increment the hour and wrap |
| ackerden | 25:863e6ef1245f | 68 | // back to 0 if it goes above 23 (i.e. past midnight). |
| ackerden | 25:863e6ef1245f | 69 | if (hours > 23) { |
| ackerden | 25:863e6ef1245f | 70 | hours = 0; |
| ackerden | 25:863e6ef1245f | 71 | } |
| ackerden | 25:863e6ef1245f | 72 | } |
| ackerden | 25:863e6ef1245f | 73 | /* }}*/ |