Crowpi word clock

Got a programming project in mind? Tell everyone about it!
Post Reply
2600Sam
Posts: 21
Joined: Thu Jul 30, 2020 6:04 am

Crowpi word clock

Post by 2600Sam »

my little python project I was working on during the lockdown (Movement Control Order here)
the code is far from perfect but it ... works!!
the attached file
word.clock.face.zip
(4.15 KiB) Downloaded 33 times
contains an .svg file for the face (setup for A4 paper)
use inkscape or your favorite .svg editor to print it out and place on top of your 8x8 LED Matrix
to read the clock the five-minute intervals are displayed at the top, there are up to 4 asterisks
to make the time more precise (add them to the five-minute interval displayed) and that will be
either how many minutes PAST the current hour or TO the next hour and then the hour on the lower half

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# copyleft 30-07-2020 Sam Sheeley
# display layout see the overlay.svg file 
#   01234567
# 0 STWENTYS
# 1 FIVEHALF
# 2 FIFTEEN*
# 3 PASTO***
# 4 FIVEIGHT
# 5 SIXTHREE
# 6 TWELEVEN
# 7 FOURNINE
#

from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
import time
import datetime
serial = spi(port=0, device=1, gpio=noop())
# rotate the display x3 so it can be read while in front of the crowpi
device = max7219(serial, cascaded=1,  block_orientation=0, rotate=3)
device.contrast(1 * 16)  #  low intensity i user 70g white paper for the face


def getadd(minute): #  1-4 additive minutes for precision
    while 5:
        if minute > 5:
            minute -= 5
        else:
            break
    additive = minute
    return additive

def face(hour, minute):
    # draw the face according to the current time
    # to the new hour or passing the old hour
    with canvas(device) as draw:
        if minute > 0 and minute < 31: #past
            # print('past')
            draw.point((0,3), fill=1)
            draw.point((1,3), fill=1)
            draw.point((2,3), fill=1)
            draw.point((3,3), fill=1)
        if minute > 30 and minute < 60:  # to
            # print('to')
            draw.point((3,3), fill=1)
            draw.point((4,3), fill=1)
            hour += 1
        if hour > 12:
            hour -= 12
            # print(hour)
        # display five minute increments for minutes
        if minute > 4 and minute < 10  or minute < 30 and minute > 24 or minute < 36 and minute > 30 or minute > 50 and minute < 56:
            draw.point((0,1), fill=1)
            draw.point((1,1), fill=1)
            draw.point((2,1), fill=1)
            draw.point((3,1), fill=1)
            # print('five')
        if minute < 15 and minute > 9 or minute < 51 and minute > 45:
            draw.point((1,0), fill=1)
            draw.point((3,0), fill=1)
            draw.point((4,0), fill=1)
            # print('ten')
        if minute < 20 and minute > 14 or minute < 46 and minute > 40:
            draw.point((0,2), fill=1)
            draw.point((1,2), fill=1)
            draw.point((2,2), fill=1)
            draw.point((3,2), fill=1)
            draw.point((4,2), fill=1)
            draw.point((5,2), fill=1)
            draw.point((6,2), fill=1)
            # print('fifteen')
        if minute < 30 and minute > 19 or minute < 41 and minute > 30:
            draw.point((1,0), fill=1)
            draw.point((2,0), fill=1)
            draw.point((3,0), fill=1)
            draw.point((4,0), fill=1)
            draw.point((5,0), fill=1)
            draw.point((6,0), fill=1)
            # print('twenty')
        if minute < 31 and minute > 29:
            draw.point((4,1), fill=1)
            draw.point((5,1), fill=1)
            draw.point((6,1), fill=1)
            draw.point((7,1), fill=1)
            # print('half')
        # display the hour in munbers
        if hour == 1:  # one
            draw.point((1,7), fill=1)
            draw.point((4,7), fill=1)
            draw.point((7,7), fill=1)
        if hour == 2:  # two
            draw.point((0,6), fill=1)
            draw.point((1,6), fill=1)
            draw.point((1,7), fill=1)
        if hour == 3:  # three
            draw.point((3,5), fill=1)
            draw.point((4,5), fill=1)
            draw.point((5,5), fill=1)
            draw.point((6,5), fill=1)
            draw.point((7,5), fill=1)
        if hour == 4:  # four
            draw.point((0,7), fill=1)
            draw.point((1,7), fill=1)
            draw.point((2,7), fill=1)
            draw.point((3,7), fill=1)
        if hour == 5:  # five
            draw.point((0,4), fill=1)
            draw.point((1,4), fill=1)
            draw.point((2,4), fill=1)
            draw.point((3,4), fill=1)
        if hour == 6:  # six
            draw.point((0,5), fill=1)
            draw.point((1,5), fill=1)
            draw.point((2,5), fill=1)
        if hour == 7:  # seven
            draw.point((0,5), fill=1)
            draw.point((4,6), fill=1)
            draw.point((5,6), fill=1)
            draw.point((6,6), fill=1)
            draw.point((7,6), fill=1)
        if hour == 8:  # eight
            draw.point((3,4), fill=1)
            draw.point((4,4), fill=1)
            draw.point((5,4), fill=1)
            draw.point((6,4), fill=1)
            draw.point((7,4), fill=1)
        if hour == 9:  # nine
            draw.point((4,7), fill=1)
            draw.point((5,7), fill=1)
            draw.point((6,7), fill=1)
            draw.point((7,7), fill=1)
        if hour == 10:  # ten
            draw.point((7,4), fill=1)
            draw.point((7,5), fill=1)
            draw.point((7,6), fill=1)
        if hour == 11:  # eleven
            draw.point((2,6), fill=1)
            draw.point((3,6), fill=1)
            draw.point((4,6), fill=1)
            draw.point((5,6), fill=1)
            draw.point((6,6), fill=1)
            draw.point((7,6), fill=1)
        if hour == 12:  # twelve
            draw.point((0,6), fill=1)
            draw.point((1,6), fill=1)
            draw.point((2,6), fill=1)
            draw.point((3,6), fill=1)
            draw.point((5,6), fill=1)
            draw.point((6,6), fill=1)

        #fine tune the minutes
        additive = getadd(minute)
        #print(additive)
        if additive < 5:
            if additive == 1:
                if minute < 31:
                    draw.point((5,3), fill=1)
                elif minute > 30:
                    draw.point((5,3), fill=1)
                    draw.point((6,3), fill=1)
                    draw.point((7,3), fill=1)
                    draw.point((7,2), fill=1)
            if additive == 2:
                if minute < 31:
                    draw.point((5,3), fill=1)
                    draw.point((6,3), fill=1)
                elif minute > 30:
                    draw.point((5,3), fill=1)
                    draw.point((6,3), fill=1)
                    draw.point((7,3), fill=1)
            if additive == 3:
                if minute < 31:
                    draw.point((5,3), fill=1)
                    draw.point((6,3), fill=1)
                    draw.point((7,3), fill=1)
                elif minute > 30:
                    draw.point((5,3), fill=1)
                    draw.point((6,3), fill=1)
            if additive == 4:
                if minute < 31:
                    draw.point((5,3), fill=1)
                    draw.point((6,3), fill=1)
                    draw.point((7,3), fill=1)
                    draw.point((7,2), fill=1)
                elif minute > 30:
                    draw.point((5,3), fill=1)
        newminute = minute + 1
        if newminute == 60:
            newminute = 0
        return newminute

def main():
    # draw the face first thing
    now = datetime.datetime.now()
    hour = now.hour
    minute = now.minute
    newminute = face(hour, minute)

    while True:
        #  a do nothing loop till the next minute no sleeping on the job here
        now = datetime.datetime.now()
        hour = now.hour
        minute = now.minute
        if minute == newminute:
            newminute = face(hour, minute)

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        # clear the matrix for exit
        device.cleanup()

2600Sam
Posts: 21
Joined: Thu Jul 30, 2020 6:04 am

Re: Crowpi word clock

Post by 2600Sam »

So I took my word clock to the next level
I modified the above python script a little
1) to use a waveshare i2c 8x8 led matrix
2) and a chronodor (adafruit chronodot knockoff) i2c rtc (real-time clock)
3) Adafruit Trinket M0 with circuit python on it
I needed some way to set the clock so two(2) buttons on the back and a few extra lines of code
instead of using a watch battery to provide backup power to the rtc I used an LC14500 rechargeable 3.7Vdc battery (same size as the AA battery)
and an old small gutted clock case.
It does need an external power source; USB connection from a computer or a standard phone charger (with micro usb connection)
front.jpg
front.jpg (144.41 KiB) Viewed 73 times
back.jpg
back.jpg (92.73 KiB) Viewed 73 times

Post Reply