View project on Hackaday View project on GitHub

Hack Clock

A hackable alarm clock, built for experimentation and learning

Lesson Two: Keep Updating the Current Time<

Instead of any old number, our display should provide us with the current time. Let's drag our numbers for the LED Display into the trash, so we can insert something new in.

Let's click on the "Time" drawer of our toolbox. This gives us some new blocks to work with - including "Current Hour" and "Current Minute." Drag those blocks into our LED Display Hour and LED Display Minute blocks. Hit save - you now should see the current time!

Dragging over the current minute and hour

We still don't really have a clock yet, do we? We can set it to the current time, but we want it to keep updating itself through the whole day. To do that, we need to understand functions.

A number of action blocks can be wrapped together as a function. Click on the "Functions" drawer of the toolbox and drag-over the top function block (the one that doesn't have a puzzle-piece hole at the bottom) to the workspace.

Dragging over a function block

Click on top block of the current stack of actions and drag it into our function block - like you were dragging some pancakes into an expanding taco shell. We now have a function!

Filling up a function block

Let's give this function a name, that way we can regonize it more easily. How about... "showCurrentTime."

Naming a function block

What would happen if we hit "save" right now? We would get a blank display! We set up a function, but we still need to call the function. Click on the function drawer again. This time you should see a new block - it's your function! You've created a new block out of several other blocks. Let's call your function by dragging and dropping it onto the workspace:

Calling a function block

We call the function once and it does update the display - but we want it to update our display over and over again, all throughout the day. Let's go back to the "Time" drawer, and this time drag the "Each Second from" block into our workspace. Once it is over. drag our function call into the "Each Second from" block. Finally, go back to the Time drawer once again and snap the "Clock Timer" constant onto the top of the "Each Second from" block.

Call our function every second

Save your code and wait for a minute to pass by - the clock should automatically update its display! You've officially built a digital clock.

Next up - Use the AM/PM indicator light!