Skip to content

Instantly share code, notes, and snippets.

@cowdinosaur
Created June 8, 2024 02:07
Show Gist options
  • Save cowdinosaur/d201a8185ba8401c60d873a872d8c5f1 to your computer and use it in GitHub Desktop.
Save cowdinosaur/d201a8185ba8401c60d873a872d8c5f1 to your computer and use it in GitHub Desktop.
import time
from neopixel import Neopixel
NO_OF_LEDS = 12
pixelssec = Neopixel(8, 0, 1, "GRB")
pixelsmin1 = Neopixel(11, 2, 22, "GRB")
pixelsmin2 = Neopixel(12, 3, 18, "GRB")
rtc = machine.RTC()
WHITE = (80, 80, 80)
YELLOW = (90, 40, 0)
RED = (90, 5, 0)
BLACK = (0, 0, 0)
def set_hour(hr):
#first hours row
hrRow1NumLights = 12
hrRow1Remainder = hr//5
#second hour row
hrRow2NumLights = 12
hrRow2Remainder = hr%5
pixelshr1 = Neopixel(hrRow1NumLights, 1, 9, "GRB")
pixelshr1.set_pixel_line(0, hrRow1NumLights - 1, BLACK)
for i in range(hrRow1Remainder):
pixelshr1.set_pixel(hrRow1NumLights - 3*i - 2, RED)
pixelshr1.set_pixel(hrRow1NumLights - 3*i - 3, RED)
pixelshr1.show()
pixelshr2= Neopixel(hrRow2NumLights, 1, 13, "GRB")
pixelshr2.set_pixel_line(0, hrRow2NumLights - 1, BLACK)
for i in range(hrRow2Remainder):
pixelshr2.set_pixel(hrRow2NumLights - 3*i - 2, RED)
pixelshr2.set_pixel(hrRow2NumLights - 3*i - 3, RED)
pixelshr2.show()
def set_min(mins):
minRow1NumLights = 11
minRow2NumLights = 12
minRow1Remainder = mins // 5
minRow2Remainder = mins % 5
pixelsmin1.set_pixel_line(0, minRow1NumLights - 1, BLACK)
for i in range(minRow1Remainder):
if (i + 1) % 3 == 0:
pixelsmin1.set_pixel(minRow1NumLights - i - 1, RED)
else:
pixelsmin1.set_pixel(minRow1NumLights - i - 1, YELLOW)
pixelsmin2.set_pixel_line(0, minRow2NumLights - 1, BLACK)
for i in range(minRow2Remainder):
pixelsmin2.set_pixel(minRow1NumLights - 3*i - 1, YELLOW)
pixelsmin2.set_pixel(minRow1NumLights - 3*i - 2, YELLOW)
pixelsmin1.show()
pixelsmin2.show()
def set_sec(secs):
if secs%2 == 1:
pixelssec.set_pixel_line(0, 8, YELLOW)
else:
pixelssec.set_pixel_line(0, 8, BLACK)
pixelssec.show()
while True:
timestamp = rtc.datetime()
_, _, _, _, hr, mins, secs, _ = timestamp
print("The time now is" ,hr, ":", mins, ":", secs)
time.sleep(0.3)
set_sec(secs)
set_min(secs)
set_hour(secs % 24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment