A Real Time Clock in Vpython - by Mannat Kaur, Sophomore in High School

by mannatkaur in Circuits > Clocks

216 Views, 0 Favorites, 0 Comments

A Real Time Clock in Vpython - by Mannat Kaur, Sophomore in High School

clockkk.PNG

Tick... Tock...Tick... Tock... Tick... Tock!

What's the time?

It's just about 9 pm my Vpython Real Time clock!

You want to know how to make it? Well, you've landed at the right place. This Instructable shows you a Visual Python based Real time clock!


Want to watch the real time clock that I made? Well, go watch it from the files attached

Supplies

To make this project, you just need

1) Visual Studio Code

2) Vpython library (to know more about this library, check this out - https://vpython.org/)

and finally, the right enthusiasm and mindset to do some math to the get clock just right!

Understanding the Math!

WhatsApp Image 2023-02-19 at 12.28.37 AM.jpeg
WhatsApp Image 2023-02-19 at 12.43.38 AM.jpeg

The images added above include all the Math needed to make the clock just right, a clock that keeps ticking, one that flies over us and keeps everything from happening at once :))

1) SecondAngle = - [seconds/60] × 2π+ π/2 (this equation depicts the fraction of the whole circle that we want to traverse)

2) MinuteAngle = - [minutes/60] × 2π+ π/2

3) HourAngle = - [hours/12] × 2π+ π/2

In python and in trigonometry in general, the positive x-axis is the 0 degrees angle but for a clock the 0 angle is straight up, which is why π/2 has been added to each equation.


Now, we need to add to 'minutes' and 'hours', what fraction of the minute and hour we have respectively.

4) DecimalMin = seconds/60

5) DecimalHour = minutes/60

6) MinuteAngle = - [minutes+ DecimalMin/60] × 2π+ π/2

3) HourAngle = - [hours + DecimalHour/12] × 2π+ π/2

Also,

Angle = π/2

AngleIncrement = - (2π/12)

Angle = Angle + AngleIncrement

The x and y coordinates on the circle as marked in the second image above are -

x = R cos (Angle)

y = R sin (Angle)

Code

In order to code a real time watch with the tick tock sound, we need to write the code for the following -

1) Import Essentials

2) Initialise Tick Sound frequency and duration

3) Initialise Tock Sound frequency and duration

4) Initialise dimensions of the clock which includes clock radius, clock thickness

5) Major Tick Marks

6) Minor Tick Marks

7) Initialise Clock Hand dimensions

8) Initialise Physical attributes

9) Generate Major Tick marks

10) Generate Minor Tick marks

11) Generate Clock Hands

12) Initialise the Start Angle i.e π/2

13) Initialise Tick Tock Timer

14) Take the time for the system's Localtime

15) Initialise Hand positions

16) Tick Tock Audio using winsound


The code is attached below.

Downloads

And... It's Done!

You have just made a basic clock that works just right! Now its upon you to add in any color, shape and design to it. Vpython gives you the freedom to do anything and everything from changing the RGB values, the design, shape, making the hands of the clock pointed or curved, etc.... Go try it out!

Now make this Clock an ALARM Clock and use it to get up every morning! I have combined this clock made in vpython with Arduino and have integrated it into a hardware. You do it too!


~ Mannat Kaur, Sophomore in High School (Grade X)