From: jimmy Date: Tue, 25 Jun 2024 01:23:04 +0000 (-0500) Subject: clock script and service X-Git-Url: https://vault307.fbx.one/gitweb/Clock-time.git/commitdiff_plain?ds=sidebyside clock script and service --- d9bd55163eac1cd92b1d307c4730b96a73587601 diff --git a/README b/README new file mode 100644 index 0000000..88e5df9 --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +clock-time.py runs led panel (already modified to fit panel) +clock-time.service -> copy to home folder, move to: +/etc/systemd/system \ No newline at end of file diff --git a/clock-time.py b/clock-time.py new file mode 100644 index 0000000..6c2e53f --- /dev/null +++ b/clock-time.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python + +import colorsys +import datetime +import time +import random +from sys import exit +from PIL import Image, ImageDraw, ImageFont +import unicornhathd + + +#FONT = ('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 10) +FONT = ('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf', 10) + +width, height = unicornhathd.get_shape() + +unicornhathd.rotation(270) +unicornhathd.brightness(0.25) + +text_x = 0 +text_y = -2 +offset = 8 + +font_file, font_size = FONT + +SAMPLE_CHARACTER = '0' + +font = ImageFont.truetype(font_file, font_size) +text_width, text_height = font.getsize(SAMPLE_CHARACTER) + +text_width += width + text_x + +try: + while True: + current_hour = datetime.datetime.now().strftime('%I') + current_minute = datetime.datetime.now().strftime('%M') + current_seconds = int(datetime.datetime.now().strftime('%S')) * 2 + + try: + active_minute + except NameError: + active_minute = int(current_minute) + r_value = random.randint(50, 255) + g_value = random.randint(50, 255) + b_value = random.randint(50, 255) + + if int(current_minute) != active_minute: + active_minute = int(current_minute) + if active_minute % 5 == 0: + r_value = random.randint(50, 255) + g_value = random.randint(50, 255) + b_value = random.randint(50, 255) + + rgb_values = [r_value, g_value, b_value] + fill_values = (rgb_values[0], rgb_values[1], rgb_values[2]) + + TEXT_UL = current_hour[0] + TEXT_UR = current_hour[1] + TEXT_LL = current_minute[0] + TEXT_LR = current_minute[1] + + image = Image.new('RGB', (text_width, max(height, text_height)), (0, 0, 0)) + + draw = ImageDraw.Draw(image) + draw.text((text_x, text_y), TEXT_UL, fill=fill_values, font=font) + draw.text((text_x + offset, text_y), TEXT_UR, fill=fill_values, font=font) + draw.text((text_x, text_y + offset), TEXT_LL, fill=fill_values, font=font) + draw.text((text_x + offset, text_y + offset), TEXT_LR, fill=fill_values, font=font) + + unicornhathd.clear() + + for x in range(width): + for y in range(height): + pixel = image.getpixel((x, y)) + r, g, b = [int(n) for n in pixel] + unicornhathd.set_pixel(width - 1 - x, y, r, g, b) + + unicornhathd.show() + + time.sleep(1) + +except KeyboardInterrupt: + unicornhathd.off() diff --git a/clock-time.service b/clock-time.service new file mode 100644 index 0000000..32afa87 --- /dev/null +++ b/clock-time.service @@ -0,0 +1,14 @@ +[Unit] +Description=clock-time +After=network-online.target + +[Service] +ExecStart=/usr/bin/python3 -u clock-time.py +WorkingDirectory=/home/pi/Pimoroni/clock +StandardOutput=inherit +StandardError=inherit +Restart=always +User=pi + +[Install] +WantedBy=multi-user.target \ No newline at end of file