61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import re
|
|
import time
|
|
|
|
from luma.led_matrix.device import max7219
|
|
from luma.core.interface.serial import spi, noop
|
|
from luma.core.render import canvas
|
|
from luma.core.legacy import text
|
|
from luma.core.legacy.font import SIXBYEIGHT_FONT, SIXBYEIGHTTHIN_FONT
|
|
|
|
class MAX7219:
|
|
__doublePoint = False
|
|
__brightness = 1.0 # default to min brightness
|
|
|
|
def __init__(self, brightness):
|
|
self.__brightness = brightness
|
|
serial = spi(port=0, device=0, gpio=noop())
|
|
self.__device = max7219(serial, cascaded=4, block_orientation=-90, rotate=0) # last arg is rotate: 0,1,2 or 3)
|
|
|
|
|
|
def Clear(self):
|
|
with canvas(self.__device) as draw:
|
|
draw.point((15,2), fill=None)
|
|
|
|
def showclock(self,tstr):
|
|
with canvas(self.__device) as draw:
|
|
text(draw, (0 ,0), tstr[0] , fill="white", font=SIXBYEIGHTTHIN_FONT)
|
|
text(draw, (8 ,0), tstr[1] , fill="white", font=SIXBYEIGHTTHIN_FONT)
|
|
text(draw, (17,0), tstr[3] , fill="white", font=SIXBYEIGHTTHIN_FONT)
|
|
text(draw, (25,0), tstr[4] , fill="white", font=SIXBYEIGHTTHIN_FONT)
|
|
if tstr[2]==':':
|
|
draw.point((15,2), fill="white")
|
|
draw.point((15,5), fill="white")
|
|
|
|
|
|
def SetBrightnessRaw(self, brightness):
|
|
"""Accepts raw brightness from 0 - 255"""
|
|
self.__device.contrast(brightness)
|
|
|
|
def ShowDoublepoint(self, on):
|
|
"""Show or hide double point divider"""
|
|
if(self.__doublePoint != on):
|
|
self.__doublePoint = on
|
|
draw.point((15,2), fill="white")
|
|
draw.point((15,5), fill="white")
|
|
|
|
def cleanup(self):
|
|
self.__brightness=0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
# demo()
|
|
showclock("01:23")
|
|
wait=raw_input("enter")
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|