First working copy - needs networking code and webserver
This commit is contained in:
36
font.py
36
font.py
@@ -1,5 +1,3 @@
|
||||
import pickle
|
||||
|
||||
font = {
|
||||
|
||||
' ':(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), # <space>
|
||||
@@ -98,7 +96,7 @@ font = {
|
||||
|
||||
'O':(0x00,0x00,0x00,0x00,0x03,0xE0,0x07,0xF0,0x0E,0x38,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x0E,0x38,0x07,0xF0,0x03,0xE0,0x00,0x00,0x00,0x00), # O
|
||||
|
||||
'O':(0x00,0x00,0x00,0x00,0x03,0xE0,0x07,0xF0,0x0E,0x38,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x0E,0x38,0x07,0xF0,0x03,0xE0,0x00,0x00,0x00,0x00), # O
|
||||
'P':(0x00,0x00,0x00,0x00,0x1F,0xF0,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0F,0xF0,0x0F,0xF0,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x1F,0x00,0x00,0x00,0x00,0x00), # P
|
||||
|
||||
'Q':(0x00,0x00,0x00,0x00,0x03,0xE0,0x0F,0x78,0x0E,0x38,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x7C,0x1C,0xFC,0x0F,0xF8,0x0F,0xF8,0x00,0x38,0x00,0xFC,0x00,0x00), # Q
|
||||
|
||||
@@ -110,5 +108,35 @@ def Letter(Letter):
|
||||
|
||||
'U':(0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00), # U
|
||||
|
||||
'V':(0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0E,0xE0,0x07,0xC0,0x03,0x80,0x00,0x00,0x00,0x00), # V
|
||||
|
||||
'W':(0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x9C,0x1C,0x9C,0x1C,0x9C,0x0F,0xF8,0x0F,0xF8,0x07,0x70,0x07,0x70,0x00,0x00,0x00,0x00), # W
|
||||
|
||||
'X':(0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0E,0xE0,0x07,0xC0,0x03,0x80,0x03,0x80,0x07,0xC0,0x0E,0xE0,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x00,0x00,0x00,0x00), # X
|
||||
|
||||
'Y':(0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0E,0xE0,0x07,0xC0,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x0F,0xE0,0x00,0x00,0x00,0x00), # Y
|
||||
|
||||
|
||||
'Z':(0x00,0x00,0x00,0x00,0x1F,0xF8,0x1C,0x38,0x18,0x38,0x10,0x70,0x00,0xE0,0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x08,0x1C,0x18,0x1C,0x38,0x1F,0xF8,0x00,0x00,0x00,0x00), # Z
|
||||
|
||||
'[':(0x00,0x00,0x00,0x00,0x07,0xF0,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0xF0,0x00,0x00,0x00,0x00), # [
|
||||
|
||||
'\\':(0x00,0x00,0x00,0x00,0x10,0x00,0x18,0x00,0x1C,0x00,0x0E,0x00,0x07,0x00,0x03,0x80,0x01,0xC0,0x00,0xE0,0x00,0x70,0x00,0x38,0x00,0x1C,0x00,0x07,0x00,0x00,0x00,0x00), # <backslash>
|
||||
|
||||
']':(0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x07,0xF0,0x00,0x00,0x00,0x00), # ]
|
||||
|
||||
'^':(0x00,0x00,0x01,0x80,0x03,0xC0,0x07,0xE0,0x0E,0x70,0x1C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), # ^
|
||||
|
||||
'_':(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x7F,0xFF), # _
|
||||
|
||||
'`':(0x00,0x00,0x00,0x00,0x1C,0x00,0x1C,0x00,0x07,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), # `
|
||||
|
||||
'a':(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x00,0x70,0x00,0x70,0x0F,0xF0,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xD8,0x00,0x00,0x00,0x00), # a
|
||||
|
||||
'b':(0x00,0x00,0x00,0x00,0x1E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0F,0xF0,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x1B,0xF0,0x00,0x00,0x00,0x00), # b
|
||||
|
||||
'c':(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70,0x1C,0x70,0x1C,0x00,0x1C,0x00,0x1C,0x70,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00), # c
|
||||
|
||||
'd':(0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x70,0x00,0x70,0x00,0x70,0x0F,0xF0,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x0F,0xD8,0x00,0x00,0x00,0x00), # d
|
||||
|
||||
'e':(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70,0x1C,0x70,0x1F,0xF0,0x1C,0x00,0x1C,0x70,0x1C,0x70,0x0F,0xE0,0x00,0x00,0x00,0x00), # e
|
||||
|
||||
112
helpers.py
Normal file
112
helpers.py
Normal file
@@ -0,0 +1,112 @@
|
||||
import settings
|
||||
|
||||
|
||||
|
||||
def Time2Sentence(TimeArray):
|
||||
|
||||
minute=TimeArray[4]
|
||||
|
||||
hour=(TimeArray[3]+settings.timezone)%24
|
||||
|
||||
MinuteString=["",
|
||||
|
||||
"m1 past",
|
||||
|
||||
"m2 past",
|
||||
|
||||
"m3 past",
|
||||
|
||||
"m4 past",
|
||||
|
||||
"m5 past",
|
||||
|
||||
"m6 past",
|
||||
|
||||
"m7 past",
|
||||
|
||||
"m8 past",
|
||||
|
||||
"m9 past",
|
||||
|
||||
"m10 past",
|
||||
|
||||
"m11 past",
|
||||
|
||||
"m12 past",
|
||||
|
||||
"m13 past",
|
||||
|
||||
"m14 past",
|
||||
|
||||
"quarter past",
|
||||
|
||||
"m16 past",
|
||||
|
||||
"m17 past",
|
||||
|
||||
'm18 past',
|
||||
|
||||
'm19 past',
|
||||
|
||||
'm20 past',
|
||||
|
||||
'm20 m1 past',
|
||||
|
||||
'm20 m2 past',
|
||||
|
||||
'm20 m3 past',
|
||||
|
||||
'm20 m4 past',
|
||||
|
||||
'm20 m5 past',
|
||||
|
||||
'm20 m6 past',
|
||||
|
||||
'm20 m7 past',
|
||||
|
||||
'm20 m8 past',
|
||||
|
||||
'm20 m9 past',
|
||||
|
||||
'half past',
|
||||
|
||||
'm20 m9 to',
|
||||
|
||||
'm20 m8 to',
|
||||
|
||||
'm20 m7 to',
|
||||
|
||||
'm20 m6 to',
|
||||
|
||||
'm20 m5 to',
|
||||
|
||||
'm20 m4 to',
|
||||
|
||||
'm20 m3 to',
|
||||
|
||||
'm20 m2 to',
|
||||
|
||||
'm20 m1 to',
|
||||
|
||||
'm20 to',
|
||||
|
||||
'm19 to',
|
||||
|
||||
'm18 to',
|
||||
|
||||
'm17 to',
|
||||
|
||||
'm16 to',
|
||||
|
||||
'quarter to',
|
||||
|
||||
'm14 to',
|
||||
|
||||
'm13 to',
|
||||
|
||||
'm12 to',
|
||||
|
||||
'm11 to',
|
||||
|
||||
'm10 to',
|
||||
|
||||
53
main.py
53
main.py
@@ -1,19 +1,46 @@
|
||||
import matrixclock
|
||||
|
||||
import machine,neopixel
|
||||
|
||||
import machine,neopixel
|
||||
|
||||
import settings
|
||||
|
||||
import ntptime
|
||||
|
||||
import network
|
||||
|
||||
import time
|
||||
|
||||
from helpers import Time2Sentence
|
||||
|
||||
import pickle
|
||||
|
||||
import random
|
||||
|
||||
|
||||
|
||||
def Test(Display,Speed=0,Type=1):
|
||||
|
||||
if Type == 1:
|
||||
|
||||
for h in range(24):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
np=neopixel.NeoPixel(machine.Pin(14),16)
|
||||
|
||||
np[0]=(25,0,0)
|
||||
|
||||
for m in range(60):
|
||||
|
||||
np[2]=(25,25,0)
|
||||
|
||||
np[4]=(0,25,0)
|
||||
print(Time2Sentence((2021,12,4,h,m)))
|
||||
|
||||
Display.WriteSentence(Time2Sentence((2021,12,4,h,m)),(60,60,60))
|
||||
|
||||
time.sleep(Speed)
|
||||
|
||||
if Type == 2:
|
||||
|
||||
for i in range(Display.number):
|
||||
|
||||
Display.np[i]=(255,255,255)
|
||||
|
||||
Display.np.write()
|
||||
|
||||
time.sleep(Speed)
|
||||
|
||||
Display.np[i]=(0,0,0)
|
||||
|
||||
|
||||
191
matrixclock/Display.py
Normal file
191
matrixclock/Display.py
Normal 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
|
||||
1
matrixclock/__init__.py
Normal file
1
matrixclock/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from matrixclock.Display import Display
|
||||
2
settings.py
Normal file
2
settings.py
Normal file
@@ -0,0 +1,2 @@
|
||||
timezone=2
|
||||
|
||||
Reference in New Issue
Block a user