older library
Dependencies: mbed DigitDisplay
main.cpp@0:20e070e8ecca, 2014-02-08 (annotated)
- Committer:
- seeed
- Date:
- Sat Feb 08 05:56:25 2014 +0000
- Revision:
- 0:20e070e8ecca
- Child:
- 1:e0b028efe6db
initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seeed | 0:20e070e8ecca | 1 | #include "mbed.h" |
seeed | 0:20e070e8ecca | 2 | #include "DigitDisplay.h" |
seeed | 0:20e070e8ecca | 3 | |
seeed | 0:20e070e8ecca | 4 | DigitalOut myled(LED1); |
seeed | 0:20e070e8ecca | 5 | |
seeed | 0:20e070e8ecca | 6 | DigitDisplay display(P1_14, P1_13); |
seeed | 0:20e070e8ecca | 7 | |
seeed | 0:20e070e8ecca | 8 | Ticker tick; |
seeed | 0:20e070e8ecca | 9 | |
seeed | 0:20e070e8ecca | 10 | uint8_t hour = 20; |
seeed | 0:20e070e8ecca | 11 | uint8_t minute = 14; |
seeed | 0:20e070e8ecca | 12 | uint8_t second = 0; |
seeed | 0:20e070e8ecca | 13 | |
seeed | 0:20e070e8ecca | 14 | void beat() |
seeed | 0:20e070e8ecca | 15 | { |
seeed | 0:20e070e8ecca | 16 | static uint8_t colon = 0; |
seeed | 0:20e070e8ecca | 17 | |
seeed | 0:20e070e8ecca | 18 | display.setColon(colon); |
seeed | 0:20e070e8ecca | 19 | if (colon) { |
seeed | 0:20e070e8ecca | 20 | second++; |
seeed | 0:20e070e8ecca | 21 | if (second >= 60) { |
seeed | 0:20e070e8ecca | 22 | second = 0; |
seeed | 0:20e070e8ecca | 23 | minute++; |
seeed | 0:20e070e8ecca | 24 | if (minute >= 60) { |
seeed | 0:20e070e8ecca | 25 | minute = 0; |
seeed | 0:20e070e8ecca | 26 | |
seeed | 0:20e070e8ecca | 27 | hour++; |
seeed | 0:20e070e8ecca | 28 | if (hour >= 24) { |
seeed | 0:20e070e8ecca | 29 | hour = 0; |
seeed | 0:20e070e8ecca | 30 | } |
seeed | 0:20e070e8ecca | 31 | display.write(0, hour / 10); |
seeed | 0:20e070e8ecca | 32 | display.write(1, hour % 10); |
seeed | 0:20e070e8ecca | 33 | } |
seeed | 0:20e070e8ecca | 34 | display.write(2, minute / 10); |
seeed | 0:20e070e8ecca | 35 | display.write(3, minute % 10); |
seeed | 0:20e070e8ecca | 36 | } |
seeed | 0:20e070e8ecca | 37 | } |
seeed | 0:20e070e8ecca | 38 | colon = 1 - colon; |
seeed | 0:20e070e8ecca | 39 | } |
seeed | 0:20e070e8ecca | 40 | |
seeed | 0:20e070e8ecca | 41 | int main() { |
seeed | 0:20e070e8ecca | 42 | display.write(0, hour / 10); |
seeed | 0:20e070e8ecca | 43 | display.write(1, hour % 10); |
seeed | 0:20e070e8ecca | 44 | display.write(2, minute / 10); |
seeed | 0:20e070e8ecca | 45 | display.write(3, minute % 10); |
seeed | 0:20e070e8ecca | 46 | display.setColon(true); |
seeed | 0:20e070e8ecca | 47 | tick.attach(&beat, 0.5); |
seeed | 0:20e070e8ecca | 48 | while(1) { |
seeed | 0:20e070e8ecca | 49 | myled = 1; |
seeed | 0:20e070e8ecca | 50 | wait(0.5); |
seeed | 0:20e070e8ecca | 51 | myled = 0; |
seeed | 0:20e070e8ecca | 52 | wait(0.5); |
seeed | 0:20e070e8ecca | 53 | } |
seeed | 0:20e070e8ecca | 54 | } |