Freedom Seeed Grove 4-Digit Display Example
Dependencies: DigitDisplay mbed
Fork of frdm_Grove_4-Digit-Display_Example by
Simply Import this Program
into your mbed compiler
Select Compile
to generate the binary file
Plug the Grove Shield v2 on the top of your FRDM-K64F
Connect on end of the 4-pin Grove cable to the 4-digit display module and the other end to the port D2 of the Grove Adapter
.
Drag n drop the frdm_Grove_4-Digit-Display_Example_K64F.bin
into the mbed drive from your file explorer
Wait for download to complete
Press the Reset/SW1 button of your FRDM-K64F board
to launch the program
The screen should start displaying a clock with time defined at 20:14 and middle dots blinking every seconds (see picture below)!!
Diff: main.cpp
- Revision:
- 0:06b1107d127e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jan 01 17:19:06 2016 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" +#include "DigitDisplay.h" + +DigitalOut myled(LED1); + +DigitDisplay display(D2, D3); + +Ticker tick; + +uint8_t hour = 20; +uint8_t minute = 14; +uint8_t second = 0; + +void beat() +{ + 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; + } + display.write(0, hour / 10); + display.write(1, hour % 10); + } + display.write(2, minute / 10); + display.write(3, minute % 10); + } + } + colon = 1 - colon; +} + +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); + } +}