Freedom Seeed Grove 4-Digit Display Example

Dependencies:   DigitDisplay mbed

Fork of frdm_Grove_4-Digit-Display_Example by Freescale

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.

/media/uploads/GregC/4-digit1.jpg

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)!!

/media/uploads/GregC/4-digit2.jpg

Committer:
GregC
Date:
Fri Jan 01 17:19:06 2016 +0000
Revision:
0:06b1107d127e
Freedom Seeed Grove 4-Digit Display Example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregC 0:06b1107d127e 1 #include "mbed.h"
GregC 0:06b1107d127e 2 #include "DigitDisplay.h"
GregC 0:06b1107d127e 3
GregC 0:06b1107d127e 4 DigitalOut myled(LED1);
GregC 0:06b1107d127e 5
GregC 0:06b1107d127e 6 DigitDisplay display(D2, D3);
GregC 0:06b1107d127e 7
GregC 0:06b1107d127e 8 Ticker tick;
GregC 0:06b1107d127e 9
GregC 0:06b1107d127e 10 uint8_t hour = 20;
GregC 0:06b1107d127e 11 uint8_t minute = 14;
GregC 0:06b1107d127e 12 uint8_t second = 0;
GregC 0:06b1107d127e 13
GregC 0:06b1107d127e 14 void beat()
GregC 0:06b1107d127e 15 {
GregC 0:06b1107d127e 16 static uint8_t colon = 0;
GregC 0:06b1107d127e 17
GregC 0:06b1107d127e 18 display.setColon(colon);
GregC 0:06b1107d127e 19 if (colon) {
GregC 0:06b1107d127e 20 second++;
GregC 0:06b1107d127e 21 if (second >= 60) {
GregC 0:06b1107d127e 22 second = 0;
GregC 0:06b1107d127e 23 minute++;
GregC 0:06b1107d127e 24 if (minute >= 60) {
GregC 0:06b1107d127e 25 minute = 0;
GregC 0:06b1107d127e 26
GregC 0:06b1107d127e 27 hour++;
GregC 0:06b1107d127e 28 if (hour >= 24) {
GregC 0:06b1107d127e 29 hour = 0;
GregC 0:06b1107d127e 30 }
GregC 0:06b1107d127e 31 display.write(0, hour / 10);
GregC 0:06b1107d127e 32 display.write(1, hour % 10);
GregC 0:06b1107d127e 33 }
GregC 0:06b1107d127e 34 display.write(2, minute / 10);
GregC 0:06b1107d127e 35 display.write(3, minute % 10);
GregC 0:06b1107d127e 36 }
GregC 0:06b1107d127e 37 }
GregC 0:06b1107d127e 38 colon = 1 - colon;
GregC 0:06b1107d127e 39 }
GregC 0:06b1107d127e 40
GregC 0:06b1107d127e 41 int main() {
GregC 0:06b1107d127e 42 display.write(0, hour / 10);
GregC 0:06b1107d127e 43 display.write(1, hour % 10);
GregC 0:06b1107d127e 44 display.write(2, minute / 10);
GregC 0:06b1107d127e 45 display.write(3, minute % 10);
GregC 0:06b1107d127e 46 display.setColon(true);
GregC 0:06b1107d127e 47 tick.attach(&beat, 0.5);
GregC 0:06b1107d127e 48 while(1) {
GregC 0:06b1107d127e 49 myled = 1;
GregC 0:06b1107d127e 50 wait(0.5);
GregC 0:06b1107d127e 51 myled = 0;
GregC 0:06b1107d127e 52 wait(0.5);
GregC 0:06b1107d127e 53 }
GregC 0:06b1107d127e 54 }