TicTok Clock

There are 86400 seconds in a day, 31536000 seconds in a year.

image16.png

There is a little known sensing block in Scratch - Current which reports the date and time of your computer by displaying a value for each of the following:

image7.png
image22.png

We can use this unique sensing block to create a series of time-telling projects, which build upon the knowledge of angles we learned about in previous months.

This project is suitable for Beginners.


Remixing the Template

To start off, let’s pick up this template and remix it to get the Clock Sprites.

scratch.mit.edu/projects/386699684/

Be sure you type the address correctly, or you might not get the right project!

Click the Remix button to create your very own copy of the project.

Once you’ve done this, the Scratch coding window will appear.

image3.png

You should see these four sprites. 


STEP 1 - Understanding how the Current Sensor works

image14.png
image7.png

First, let’s find out how the current code block works.

You can find this current block under the sensing blocks.

Add in these code to the clock sprite:

When you press the space bar, you will see that the clock sprite will tell you the current local hour, minute, or second. The block gets the data based on the user's computer's clock and it uses 24-hour time.


STEP 2 - Using the Text-to-Speech extension to make a talking clock

image12.png

Click on Add Extension button at the bottom left of the screen.

image6.png

You will see a selection of different modules. Select the Text to Speech module:

image11.png

You will notice that you will have a new set of coding blocks called Text to Speech. Now we’ll be able to let our projects talk.


image14.png

Now, instead of just displaying the time on screen, we can have it say the time to us.

Add in these code to the clock sprite:


STEP 3 - Calculating the angles on the clock hands

We are not yet done! We are going to do a ticking clock with hour, minute and second hands.

To build such a clock, you will need to figure out how many degrees the second hand turn every second. 

From one hour to the next, how many degrees must the hour hand rotate?

How many degrees does the minute hand turn every minute?


Think before looking ahead!

Annotation 2020-04-21 231115.png

There are 360° in a full circle and there are 60 seconds in a minute.

Which means that the second hand will tick 60 times in a minute.

So there are 360° / 60 = 6° between each tick.

image15.png

Now let’s write the code for second hand. 

  1. Centre the second-hand sprite in the middle of the screen.

  2. Have the second-hand point in the correct direction based on the current second: 6° for every second.

We have also included a ticking sound for the second hand.


Now, write the code for the minute and the hour hands on your own.
The code are very similar to the second-hand code, but they don’t need to play the ticking sound.


Try before looking ahead!

If you are really stuck, we have included the correct code for each hand.

image9.png
image5.png

Challenges!

  1. On most analogue clocks with hands, the hour hand moves smoothly rather than jumping suddenly at each new hour, adjust your code to implement this more realistic movement.

  2. Create an alarm clock that takes some input from the user, and then beeps when the time is up. To store the user input, you will need to use a variable using the Variables block.

  3. Finally, in future Scratch projects, you can make custom events happen on special dates - such as Christmas and New Year! Or maybe you can make a game that can only be won at a certain time.


image5.png

Sign up for for a trial class and experience a new way to learn to code.

Join our mailing list or follow us on Facebook to stay updated with our latest projects.