This is a simple clock (hh:mm) make with the library Multi7Seg. The library and the demo software is make by 5OFT.

Dependencies:   mbed Led7Seg Multi7Seg

Committer:
trombettamichele
Date:
Sat Apr 23 10:33:59 2011 +0000
Revision:
0:0040aea2c9f6

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trombettamichele 0:0040aea2c9f6 1 #include "mbed.h"
trombettamichele 0:0040aea2c9f6 2 #include "Multi7Seg.h"
trombettamichele 0:0040aea2c9f6 3 //##### A simple Clock #####
trombettamichele 0:0040aea2c9f6 4 // Created by Michele Trombetta
trombettamichele 0:0040aea2c9f6 5 // Copyright 2010 5OFT. All rights reserved.
trombettamichele 0:0040aea2c9f6 6
trombettamichele 0:0040aea2c9f6 7 Ticker ticker_sec;
trombettamichele 0:0040aea2c9f6 8 Multi7Seg d_seconds(p21, p22, p23, p24, p25, p26, p27, p20, p19, led_ANODE);
trombettamichele 0:0040aea2c9f6 9 Multi7Seg d_minutes(p21, p22, p23, p24, p25, p26, p27, p18, p17, led_ANODE);
trombettamichele 0:0040aea2c9f6 10 DigitalOut seconds(p16);
trombettamichele 0:0040aea2c9f6 11
trombettamichele 0:0040aea2c9f6 12 unsigned int cnt_h = 0, cnt_m = 0, cnt_s = 0;
trombettamichele 0:0040aea2c9f6 13
trombettamichele 0:0040aea2c9f6 14 void inc_num() {
trombettamichele 0:0040aea2c9f6 15 cnt_s++;
trombettamichele 0:0040aea2c9f6 16 seconds = !seconds;
trombettamichele 0:0040aea2c9f6 17 if (cnt_s == 60) {
trombettamichele 0:0040aea2c9f6 18 cnt_s = 0;
trombettamichele 0:0040aea2c9f6 19 cnt_m++;
trombettamichele 0:0040aea2c9f6 20 }
trombettamichele 0:0040aea2c9f6 21 if (cnt_m == 60) {
trombettamichele 0:0040aea2c9f6 22 cnt_m = 0;
trombettamichele 0:0040aea2c9f6 23 cnt_h++;
trombettamichele 0:0040aea2c9f6 24 }
trombettamichele 0:0040aea2c9f6 25 if (cnt_h == 24) cnt_h = 0;
trombettamichele 0:0040aea2c9f6 26 }
trombettamichele 0:0040aea2c9f6 27
trombettamichele 0:0040aea2c9f6 28 int main() {
trombettamichele 0:0040aea2c9f6 29
trombettamichele 0:0040aea2c9f6 30 ticker_sec.attach(&inc_num, 1);
trombettamichele 0:0040aea2c9f6 31 seconds = 0;
trombettamichele 0:0040aea2c9f6 32 d_minutes.setformat(format_DEC);
trombettamichele 0:0040aea2c9f6 33 d_seconds.setformat(format_DEC);
trombettamichele 0:0040aea2c9f6 34 //d_seconds.setenabled(1); // Simple test to disable a single display
trombettamichele 0:0040aea2c9f6 35 while (1) {
trombettamichele 0:0040aea2c9f6 36 d_minutes.write(cnt_m);
trombettamichele 0:0040aea2c9f6 37 d_seconds.write(cnt_s);
trombettamichele 0:0040aea2c9f6 38 }
trombettamichele 0:0040aea2c9f6 39 }