Friday, April 1, 2016

4 Digit 7 Segment Clock with DS3231



Earlier this weekend I found out what a shift register was and managed to get a 4 digit 7 segment display (4D7SD) to show counting milliseconds using Kristian BlĂ„sol's videos here: Shift Register4D7SD. These two videos are fantastic and really show you how to work with these concepts, please watch them if you are interested in getting this wired up, I will only be covering my modifications to his setup. In my code you'll notice I used a cheat at the end instead of figuring out how the cathode call numbers worked.

Now I really wanted to take this a step further. My goal was to build a display that would show the current time (hh:mm) with the 4D7SD. Naturally, to do this I would need a clock (and not the millis like I used in my last post). Enter the DS3231. This is a nifty little device, I bought several on ebay (about 1.5$ for 2). They have a battery to keep time even when the board is turned off.

I used this instructable for wiring. The library linked in this will get you going with pretty much all you need with the DS3231. However, the functions in the library use pointers which, for the uninitiated, are a *****. I am not qualified to explain a pointer, but my understanding is it basically is a variable that 'points' to somewhere else. My guess in this application would be the pointer runs a functions to grab the time from the DS3231.

Anyway, the problem with the pointers is, you can't convert them to a different value. What this means for you is that the value your library takes from the DS is a 'char' not an 'int'. The end result is you have to jump through a bunch of hoops (as you'll see in my code) to get it to do what you want. You can't compare characters to integers, and a bunch of other things I can't think of right now.

No comments:

Post a Comment