Priyank Kalgaonkar
/
TALab3BsliderECE595
ECE595 - Lab 3 Part 2 - Slider Potentiometer Program - TA
main.cpp@1:93e233c997ad, 2021-01-16 (annotated)
- Committer:
- priyank12p
- Date:
- Sat Jan 16 00:47:35 2021 +0000
- Revision:
- 1:93e233c997ad
- Parent:
- 0:4cb6e9d0da34
- Child:
- 2:adc51888ece5
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
priyank12p | 1:93e233c997ad | 1 | #include "mbed.h" |
priyank12p | 1:93e233c997ad | 2 | #include "DigitDisplay.h" |
priyank12p | 1:93e233c997ad | 3 | |
priyank12p | 1:93e233c997ad | 4 | DigitalOut myled(LED1); |
priyank12p | 0:4cb6e9d0da34 | 5 | |
priyank12p | 1:93e233c997ad | 6 | DigitDisplay display(D2, D3); |
priyank12p | 1:93e233c997ad | 7 | |
priyank12p | 1:93e233c997ad | 8 | Ticker tick; |
priyank12p | 0:4cb6e9d0da34 | 9 | |
priyank12p | 1:93e233c997ad | 10 | uint8_t hour = 20; |
priyank12p | 1:93e233c997ad | 11 | uint8_t minute = 14; |
priyank12p | 1:93e233c997ad | 12 | uint8_t second = 0; |
priyank12p | 0:4cb6e9d0da34 | 13 | |
priyank12p | 1:93e233c997ad | 14 | void beat() |
priyank12p | 0:4cb6e9d0da34 | 15 | { |
priyank12p | 1:93e233c997ad | 16 | static uint8_t colon = 0; |
priyank12p | 1:93e233c997ad | 17 | display.setColon(colon); |
priyank12p | 1:93e233c997ad | 18 | if (colon) { |
priyank12p | 1:93e233c997ad | 19 | second++; |
priyank12p | 1:93e233c997ad | 20 | if (second >= 60) { |
priyank12p | 1:93e233c997ad | 21 | second = 0; |
priyank12p | 1:93e233c997ad | 22 | minute++; |
priyank12p | 1:93e233c997ad | 23 | if (minute >= 60) { |
priyank12p | 1:93e233c997ad | 24 | minute = 0; |
priyank12p | 1:93e233c997ad | 25 | |
priyank12p | 1:93e233c997ad | 26 | hour++; |
priyank12p | 1:93e233c997ad | 27 | if (hour >= 24) { |
priyank12p | 1:93e233c997ad | 28 | hour = 0; |
priyank12p | 1:93e233c997ad | 29 | } |
priyank12p | 1:93e233c997ad | 30 | display.write(0, hour / 10); |
priyank12p | 1:93e233c997ad | 31 | display.write(1, hour % 10); |
priyank12p | 1:93e233c997ad | 32 | } |
priyank12p | 1:93e233c997ad | 33 | display.write(2, minute / 10); |
priyank12p | 1:93e233c997ad | 34 | display.write(3, minute % 10); |
priyank12p | 1:93e233c997ad | 35 | } |
priyank12p | 0:4cb6e9d0da34 | 36 | } |
priyank12p | 1:93e233c997ad | 37 | colon = 1 - colon; |
priyank12p | 1:93e233c997ad | 38 | } |
priyank12p | 0:4cb6e9d0da34 | 39 | |
priyank12p | 1:93e233c997ad | 40 | int main() { |
priyank12p | 1:93e233c997ad | 41 | display.write(0, hour / 10); |
priyank12p | 1:93e233c997ad | 42 | display.write(1, hour % 10); |
priyank12p | 1:93e233c997ad | 43 | display.write(2, minute / 10); |
priyank12p | 1:93e233c997ad | 44 | display.write(3, minute % 10); |
priyank12p | 1:93e233c997ad | 45 | display.setColon(true); |
priyank12p | 1:93e233c997ad | 46 | tick.attach(&beat, 0.5); |
priyank12p | 1:93e233c997ad | 47 | while(1) { |
priyank12p | 1:93e233c997ad | 48 | myled = 1; |
priyank12p | 1:93e233c997ad | 49 | wait(0.5); |
priyank12p | 1:93e233c997ad | 50 | myled = 0; |
priyank12p | 1:93e233c997ad | 51 | wait(0.5); |
priyank12p | 1:93e233c997ad | 52 | } |
priyank12p | 1:93e233c997ad | 53 | } |