Close

The software

A project log for Numican

A numitron clock in an altoids can!

riktwriktw 11/12/2016 at 08:510 Comments

The software is MBED based and can be found here: https://developer.mbed.org/users/riktw/code/Numitron_clock/

The main file can be found here: https://developer.mbed.org/users/riktw/code/Numitron_clock/file/d1558f6f88bf/main.cpp

The clock has to do several things. First of all, it's a clock, it should keep track of the time. This is done using the STD time library to make things easy. Second, the displays have to be updated from time to time so the current time is displayed, else it's a bit of a useless clock. And third, the time has to be adjustable, so the button input has to be processed.

The code does this all in the following way:

1. keeping track of time

As mentioned, the std time library is used, MBED uses the RTC somewhere deep in the code to do this but this is all done automaticly. Just set the time with the set_time command and done. How lovely

2. displaying time.

The TLC5916's I used can be chained together. If using only one, the normal way of using it is sending 1 byte of data to it using SPI and then toggling the LE pin to latch the send data to the output of the TLC5916. When using more then one, just send more then one byte of data. Byte one will first arrive at the first TLC5916. The second byte "pushes" this byte out to the next TLC5916. The second byte will now be in the first TLC5916 and the first byte in the second TLC5916. This can be upscaled to as many TLC5916's as you want.

To display the time, every second the current time is converted to a few bytes that are then send to the TLC5916's, which then make sure the numitrons are on correctly. It also makes the dot of the second left numitron blink for a nice effect.

3. Processing buttons

There are 4 buttons, one per numitron. Pressing it will raise it with one. This gives a quick way to set the current time.

The buttons are read in using the BusIn object. This way they can be read in in a single command, which returns a number between 0 and 15 depending on the buttons pressed. The buttons are checked twice with a small 50ms delay in between to negate button bounce.

The current time is then retrieved, adjusted and set as the new current time. At the end the display is updated directly to reflect the change in time.

Because of the use of the MBED libraries the code is relatively small and easy to understand and adjust if needed.

Discussions