MBe
Published © CC BY-SA

Raspberry Pi Colour Clock with RainbowHAT

A Raspberry Pi colour clock made using Rainbow HAT.

BeginnerShowcase (no instructions)2 hours964
Raspberry Pi Colour Clock with RainbowHAT

Things used in this project

Story

Read more

Code

Clock

Python
#!/usr/bin/env python

import time
import colorsys
import rainbowhat
import subprocess

print("""zeigt die Uhr on Rainbow HAT.

0 black
1 brown
2 red
3 orange
4 yellow
5 green
6 blue
7 violet
8 grey
9 white

Press Ctrl+C or touch A to exit.

""")

#import blinkt
from rainbowhat import rainbow as blinkt

A = 0
B = 1
C = 2

inputs = [False, False, False]

@rainbowhat.touch.press()
def touch_press(channel):
    global inputs
    inputs[channel] = True
    rainbowhat.lights[channel].on()

@rainbowhat.touch.release()
def touch_release(channel):
    global inputs
    inputs[channel] = False
    rainbowhat.lights[channel].off()

colours = [
[  0,  0,  0],#0 black
[139, 69, 19],#1 brown
[255,  0,  0],#2 red
[255, 69,  0],#3 orange
[255,255,  0],#4 yellow
[  0,255,  0],#5 green
[  0,  0,255],#6 blue
[128,  0,128],#7 violet
[255,255,100],#8 grey
[255,255,255],#9 white
]

blinkt.set_clear_on_exit()

while True:
    hour = time.localtime().tm_hour
    minute = time.localtime().tm_min
    sekunde = time.localtime().tm_sec
    
    hourten = int(hour / 10)
    hourunit = int(hour % 10)
    minuteten = int(minute / 10)
    minuteunit = int(minute % 10)
    sekundeten = int(sekunde / 10)
    sekundeunit = int(sekunde % 10)

    sekundeLCD = int(sekunde + 1 )
    minuteLCD = float(minute / 100.00)

    zeit=time.strftime("%H" "%M")
        
    r, g, b = colours[hourten]
    blinkt.set_pixel(6,r,g,b)
    r, g, b = colours[hourunit]
    blinkt.set_pixel(5,r,g,b)
    

    r, g, b = colours[minuteten]
    blinkt.set_pixel(4,r,g,b)
    r, g, b = colours[minuteunit]
    blinkt.set_pixel(3,r,g,b)
    
    r, g, b = colours[sekundeten]
    blinkt.set_pixel(2,r,g,b)
    r, g, b = colours[sekundeunit]
    blinkt.set_pixel(1,r,g,b)

    r, g, b = colours[sekundeunit]
    blinkt.set_pixel(0,255,255,255)

    blinkt.show()

    time.sleep(0.5)

    blinkt.set_pixel(0,0,0,0)

    blinkt.show()

    time.sleep(0.5)

    rainbowhat.display.print_str(zeit)
    rainbowhat.display.set_decimal(1, True)
    rainbowhat.rainbow.set_all(r, g, b, brightness=0.1)
    rainbowhat.display.show()

    if inputs[C]:
        subprocess.call(["shutdown", "-h", "now"])

Credits

MBe

MBe

1 project • 0 followers
Techniker

Comments