LED Clock for Geometry Class

I made a clock run by a Raspberry Pi
It gets the current time over Wi-Fi and can print the arc length of the clock hands.

I cut the frame out of wood on the laser cutter (The frame is approximately 13.25cm in diameter), I used 60 LEDs from the 144 LED per meter strip.

I am using a Raspberry Pi Pico W to program the LEDs, the code is a modified version of the code on Doc’s GitHub. It gets the current time over Wi-Fi and tracks the time with an internal clock, sets the LEDs to simulate the clock’s hands, and prints the arc length for the seconds, minutes, and hours hands.

$$ ArcLength= 2 \pi r \cdot \frac{HandDegrees}{ 360 } $$

Doc’s original code is bad because it is specifically made for the clock he made, where there is only 59 LEDs instead of 60, so it has to jump around and skip seconds to stay accurate, also, his LED strip is counter-clockwise, so you have to figure out how to reverse his code.


import socketpool
import wifi

from adafruit_httpserver.mime_type import MIMEType
from adafruit_httpserver.request import HTTPRequest
from adafruit_httpserver.response import HTTPResponse
from adafruit_httpserver.server import HTTPServer
import adafruit_ntp

import board
import time
from ledPixelsPico import *
from uNetComm import *
from uSchedule import *
from ledClock import *
from math import pi


# brightness Knob
brightness = 1.0

#ssid, password = secrets.WIFI_SSID, secrets.WIFI_PASSWORD  # pylint: disable=no-member
ssid, password = "TFS Students", "Fultoneagles"  # pylint: disable=no-member

pool = uNetConnect(ssid, password)
server = HTTPServer(pool)
# get time
#ntp = adafruit_ntp.NTP(pool, tz_offset=0)
clock = ledClock(board.GP27, 60, pool, True)
clock.initTime()


print(f"Listening on http://{wifi.radio.ipv4_address}:80")
# Start the server.
server.start(str(wifi.radio.ipv4_address))
t_zero = time.monotonic()

while True:
    dt = time.monotonic() - t_zero
    if dt >= 1.0:
        t_zero = time.monotonic()
        dtime = time.monotonic() - clock.zeroTime
        clock.now = clock.startTime.addSecs(dtime)
        #print(dtime, clock.now)
        print(f"Time: {clock.now.hr}:{clock.now.min}:{clock.now.sec}")
        #clock.lightToTime(clock.now)
        r = (((100 / 144) * 60) / pi) / 2
        h = clock.now.hr
        m = clock.now.min
        s = clock.now.sec
        for i in range (60):
            clock.pixels[i]=(0,0,0)
        for i in range(m):
            clock.pixels[i]=(0,10,30)
            
        clock.pixels[h*5] = (100,0,0)
        clock.pixels[s-1] = (0,255,0)
        clock.show()
        hdegrees = h*30
        mdegrees = m*6
        sdegrees = s*6

        harclength = hdegrees/360*2*pi*r
        marclength = mdegrees/360*2*pi*r
        sarclength = sdegrees/360*2*pi*r

        print("arclength hours=", harclength)
        print("arclength minutes=",marclength)
        print("arclength seconds=",sarclength)

Leave a Reply