Real time Analog Clock in BananaPi24th July 2019
- Here we are going to create a simple real time analog clock using bananapi.
- To do this we are using python programming language and python turtle module.
- The turtle module is a builtin module in python, meaning you do not have to install it.
- It is used to create basic 2D shapes and drawings and is extremely beginner friendly.
- The main advantages of turtle is that it is extremely simple and makes it very easy to draw things to the screen.
- That being said the turtle module does offer support for some more advanced functionality.
- For better understanding of python turtle module visit :
- First we need to understand what is analog clock and how it works ? after that we are able to make a code for that.
- Analog clock has one dial in which 12 digits or marks are there starting from 1 to end at 12, that all are separated with each other by angle of 30 degree.
- Other than this it has 3 hands analog clock having basically indicating hour, minute and second. At every second of time hand for second moves 6 degree , at every minute hand for minute moves also 6 degree and at every 30 minutes hand for hour moves 15 degree. (This is what we are going to do in our code).
Component you require
- Banana Pi
- Class 10 micro SD card
- 5V 2A powerm supply
- Monitor screen
- HDMI cable
- Keyboard, Mouse
First of all you need to boot up your bananapi for that visit : https://bananapiblog.com/2019/05/02/how-to-install-linux-based-os-images-except-android/
- Now let’s start to make clock
- First of all import modules.
import turtle import time
- Define our screen object and modify screen
wn = turtle.Screen() wn.bgcolor("black") wn.title("Analog clock by Tanna TechBiz") wn.tracer(0)
- Now define our turtle object
pn2 = turtle.Turtle() pn2.speed(0)
- Make a clock by making a function, later on we will call that function to make a clock.
def clock(h,m,s, pn2):
#Draw dial (outer circle) pn2.up() pn2.goto(0,210) pn2.setheading(0) pn2.down() pn2.pensize(3) pn2.color("cyan") pn2.circle(-210) pn2.ht() #Draw mark on dial for i in range(12): pn2.up() pn2.goto(0,0) pn2.down() pn2.rt(30) pn2.up() pn2.fd(170) pn2.down() pn2.fd(40) #Hour hand pn2.speed(0) pn2.up() pn2.goto(0,0) pn2.color("white") angle = (h / 12)* 360 pn2.down() pn2.setheading(90) if m > 0 and m < 30: pn2.rt(angle) else: pn2.rt(angle+15) pn2.fd(60) #Minute hand pn2.speed(0) pn2.up() pn2.goto(0,0) pn2.color("magenta") angle = (m / 60)* 360 pn2.down() pn2.setheading(90) pn2.rt(angle) pn2.fd(100) #Second hand pn2.speed(0) pn2.up() pn2.goto(0,0) pn2.setheading(90) pn2.color("gray") angle = (s / 60)* 360 pn2.down() pn2.rt(angle) pn2.fd(130)
while True: h = int(time.strftime("%I")) m = int(time.strftime("%M")) s = int(time.strftime("%S"))
clock(h, m, s, pn2) pn2.st() wn.update() time.sleep(1) pn2.clear()
- By writing this you will able visualize the Real time analog clock in your bananapi screen.
Want to create your own real time analog clock? You can buy required products form Tanna Techbiz.