View project on Hackaday View project on GitHub

Hack Clock

A hackable alarm clock, built for experimentation and learning

Lesson Four: Play Lists

Now we are going to have our alarm clock play music. Once we have our amplifier and speakers wired up, it is time to create a list of audio files for our alarm clock to play.

First, let's take a look at our "Upload Audio" page by clicking on the top navigation bar. Once the page appears we should be able to see a list of files that are already loaded on our Hack Clock, and also a button to upload our own files. Right now we are going to use the two files that came with the Hack Clock - AmicusMeus.ogg and TestTrack.ogg.

Upload Audio page

Let's return back to our "Edit Code" page by clicking it in the top navigation bar. Let's create a new function, this time to play music:

The playMusic function

We want to tell the speaker what audio files play. We don't want to have just one file either - we want to provide an entire play list. We can drag over a list box from the "Lists" drawer...

Create a list

...and then resize it to have two elements:

Resize a list

Once the list block is in place, we can open up the "Audio" drawer in our toolbox and find blocks for each of our music files. Let's snap both into our list.

Add audio tracks to the list

The change in the code above will create a list with the names of two tracks, TestTrack and AmicusMeus. The next thing will be to add a new action from our "Audio" drawer in the toolbox labled "On _ Play _." For the left variable we will drag in the "Audio Speaker" variable from the "Audio" drawer:

Using the On Play action

Then we move our play list into the "On Play" action:

Adding our list to the action

Next, let's copy over the "At Time _ In Clock _" action from the "Time" drawer, along with the Clock Timer constant. Let's place the Clock Timer into the right-most argument of our action, then add two numbers from the "Math" drawer into the remaining slots of our action. Finally, we will put our new playMusic function from the "Functions" drawer inside of our action:

Clock function to play music

Excellent! Now at 8:30 in the morning our clock will begin blasting some music. Change the time to just a minute in the future - see if it will begin playing!

Now we need to learn how to add some new hardware to our clock: let's have our clock tell us the temperature outside when we press a button.