Binary Clock and Base2

Introduction

You get bored sat there waiting for that extra hardware to arrive to play around with the new toys and want something to do with your mbed???

Maybe Binary Clock!

Let me start for the uninitiated what is a binary clock, a binary clock is a regular clock, but the digits of the clock are represented in binary number format or Base2, we in general represent numbers in Base10.

so 19 in binary is 10011 (Hexadecimal or Base16 it is 0x13)

Basically the number is represented as follows:

Base10

10's 1's

1      9

Base2

16  8  4  2  1

 1  0  0  1  1

16 + 2 + 1 = 19

Base16

16's  1's

 1      3

(1*16) + (3*1) = 19

Its that simple

So for a binary clock the digits for the number are either on or off, therefore we can represent the numbers using on and off lights or in this case (as I had some lying around) LEDs.

Design

[TODO: Electronic Schematic]

BOM:

1 mbed

1 breadboard (don't waste vero or a pcb on this)

1 Blue LED (I used yellow as its all I had lying around)

6 LEDs (Not blue)

6 More LEDs (Not blue and not previous colour) (again didn't have enough)

13 1k resistors (one is missing and some are 720's due to lack of supplies)

More than likely some wire.

The electronics specifically use 1 resistor per LED, this is to maintain constant brightness of the LEDs.

 // Define your outputs
DigitalOut Sec1(p5);
DigitalOut Sec2(p7);
DigitalOut Sec4(p9);
DigitalOut Sec8(p11);
DigitalOut Sec16(p13);
DigitalOut Sec32(p15);

DigitalOut Min1(p30);
DigitalOut Min2(p28);
DigitalOut Min4(p26);
DigitalOut Min8(p24);
DigitalOut Min16(p22);
DigitalOut Min32(p21);

DigitalOut Hour1(LED4);
DigitalOut Hour2(LED3);
DigitalOut Hour4(LED2);
DigitalOut Hour8(LED1);
DigitalOut Hour16(p20);

Pins are spaced out by 2 as I used 5mm LEDs and this is so they will fit more easily.

 

[TODO: Process Flow]

The RTC is set from the Serial port via USB channel.

 Software

BinaryClock

[TODO: Detail Software]


10 comments

09 Dec 2009

You can use BusOut instead of several DigitalOuts if you need to toggle several pins at once.

10 Dec 2009

I know this was phase1

27 Feb 2010

Hi Andrew

I have been trying to get this program running without success, but forgive me this is all quite new to me and a steep learning curve!

I have set up all the leds as shown above, compiled the program with success, but nothing happens. I then opened Tera Term and the following is repeatedly displayed;

12:00 AM..........so I know that something is happening............I have tried pressing keys on the keyboard but without response.

I really think that I am making a simple mistake here, but I can`t for the life of me work out what I am doing wrong, can you help?

PS; I know that my `digital out` pins work and the leds are the right way around because I wrote a simple program to them on and off.

27 Feb 2010

It isn't perfect, sometimes the RTC counter initialises to 0xFFFFFFFF and doesn't load the init routine.

I haven't looked at it for a while, If you aren't using a backup battery then you could call the init routine on power up.

27 Feb 2010

Ok, I am going to try and strip out the `serial fuctionality` in the code and try to just produce a binary clock using the leds.

It will be a good excercise for me!

thanks

Paul.

28 Feb 2010

This is already done the errors you are seeing are due to the RTC not being initialised correctly.

28 Feb 2010

Ok thanks. I think that this is a bit advanced for me at this stage.

 

28 Feb 2010

        Sec1     = (bool)(((uint8_t)tmr->tm_sec) & 0x01);
        Sec2     = (bool)((((uint8_t)tmr->tm_sec) & 0x02) >> 1);
        Sec4     = (bool)((((uint8_t)tmr->tm_sec) & 0x04) >> 2);

Hi, I am having trouble understanding this part of the code, could you post a couple of lines of comment please?

Many thanks.

01 Mar 2010 . Edited: 01 Mar 2010

Basically it acquires the time in seconds.

the & is a bit mask so it only reads if bit 1, 2 or 3 is set to true.

0xYY is Hexadecimal.

so & 0x02, if the the input in binary is 0000 1110 the output will be 0000 0010

0x04 is bit 3 just to confuse the situation, basically because of Base2.

>> is right shift.

so >> 1 is right shift, using the above value will become 0000 0001

Converting to bool results in TRUE.

01 Mar 2010

Many thanks for the explanation....and patience!

I think I get it.....its a pretty neat way of doing things. I can see I have a long way to go.

Thanks again.

You need to log in to post a comment