First working copy - needs networking code and webserver

This commit is contained in:
2021-12-15 18:17:53 +02:00
parent 9b20236eb6
commit 8495037350
8 changed files with 378 additions and 19 deletions

191
matrixclock/Display.py Normal file
View File

@@ -0,0 +1,191 @@
import machine,neopixel
from time import sleep #GOES
import font
words={"it":[0,1],
"is":[3,4],
"beer":[19,35,51],
"m1":[13,14,15],
"m2":[16,17,18],
"m3":[48,49,50,51,52],
"m4":[44,45,46,47],
"m5":[32,33,34,35],
"m6":[73,74,75],
"m7":[96,97,98,99,100],
"m8":[88,89,90,91,92],
"m9":[54,55,56,57],
"m10":[20,21,22],
"m11":[37,38,39,40,41,42],
"m12":[80,81,82,83,84,85],
"m13":[24,25,26,27,28,29,30,31],
"m14":[64,65,66,67,68,69,70,71],
"quarter":[105,106,107,108,109,110,111],
"m16":[73,74,75,76,77,78,79],
"m17":[96,97,98,99,100,101,102,103,104],
"m18":[88,89,90,91,92,93,94,95],
"m19":[54,55,56,57,58,59,60,61],
"m20":[6,7,8,9,10,11],
"half":[112,113,114,115],
"past":[117,118,119,120],
"to":[120,121],
"h1":[150,151,152],
"h2":[153,154,155],
"h3":[132,133,134,135,136],
"h4":[140,141,142,143],
"h5":[156,157,158,159],
"h6":[137,138,139],
"h7":[123,124,125,126,127],
"h8":[128,129,130,131,132],
"h9":[169,170,171,172],
"h10":[167,168,169],
"h11":[176,177,178,179,180,181],
"h12":[144,145,146,147,148,149],
"midnight":[160,161,162,163,164,165,166,167],
"in":[192,193],
"the":[195,196,197],
"morning":[208,209,210,211,212,213,214],
"afternoon":[199,200,201,202,203,204,205,206,207],
"evening":[224,225,226,227,228,229,230],
"at":[216,217],
"night":[219,220,221,222,223],
"dot":[182,183,184],
"gin":[173,174,175],
"oclock":[185,187,188,189,190,191],
"and":[232,233,234],
"cold":[236,237,238,239],
"cool":[240,241,242,243],
"warm":[245,256,257,258],
"hot":[252,253,254],
"beer":[19,35,51,67],
}
class Display(object):
"""Initialises a NeoPixel-String."""
def __init__(self,DataPin,Rows=16,Columns=16):
self.np=neopixel.NeoPixel(machine.Pin(DataPin),Rows*Columns)
self.number=Rows*Columns
self.Rows=Rows
self.Columns=Columns
def Write(self,Pos,Colour=(0,0,0), Immediate=True):
"""write(Pos,Colour=(0,0,0), Immediate=True): Writes a colour (given as an RGB triplet) to the Pixel
at position 'Pos'. If 'Immediate' is set, change immediately, otherwise, wait until the display is
explicitly written or a write with 'Immediate' is called."""
if Pos >= self.number:
print("Out of range")
else:
self.np[self.Weave(Pos)]=Colour
if Immediate:
self.np.write()
def Clear(self,color=(0,0,0),Immediate=True):
"""Clears all pixels"""
for i in range(self.number):
self.np[i]=color
if Immediate:
self.np.write()
def WriteWord(self,word,colour=(50,50,50),Immediate=False):
try:
for i in words[word]:
self.Write(i,colour,False)
if Immediate == True:
self.np.write()
except KeyError:
#print("No such word")
pass