Example program for the Seeed Grove shield, that uses Digit Display Grove on UART connector (D0/D1 pins). This program displays/measures time.

Dependencies:   DigitDisplay mbed

Fork of DigitDisplay_Clock by Seeed Studio

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Copyright (c) 2010-2011 mbed.org, MIT License
00002 *
00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004 * and associated documentation files (the "Software"), to deal in the Software without
00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007 * Software is furnished to do so, subject to the following conditions:
00008 *
00009 * The above copyright notice and this permission notice shall be included in all copies or
00010 * substantial portions of the Software.
00011 *
00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 */
00018 
00019 #include "mbed.h"
00020 #include "DigitDisplay.h"
00021 
00022 DigitalOut myled(LED1);
00023 
00024 /**
00025  * RX pin - D0
00026  * TX pin - D1
00027  */
00028 DigitDisplay display(D0, D1);
00029 
00030 Ticker tick;
00031 
00032 uint8_t hour   = 20;
00033 uint8_t minute = 14;
00034 uint8_t second = 0;
00035 
00036 void beat()
00037 {
00038     static uint8_t colon = 0;
00039     
00040     display.setColon(colon);
00041     if (colon) {
00042         second++;
00043         if (second >= 60) {
00044             second = 0;
00045             minute++;
00046             if (minute >= 60) {
00047                 minute = 0;
00048                 
00049                 hour++;
00050                 if (hour >= 24) {
00051                     hour = 0;
00052                 }
00053                 display.write(0, hour / 10);
00054                 display.write(1, hour % 10);
00055             }
00056             display.write(2, minute / 10);
00057             display.write(3, minute % 10);
00058         }
00059     }
00060     colon = 1 - colon;
00061 }
00062 
00063 int main() {
00064     display.write(0, hour / 10);
00065     display.write(1, hour % 10);
00066     display.write(2, minute / 10);
00067     display.write(3, minute % 10);
00068     display.setColon(true);
00069     tick.attach(&beat, 0.5);
00070     while(1) {
00071         myled = 1;
00072         wait(0.5);
00073         myled = 0;
00074         wait(0.5);
00075     }
00076 }