wordclock: created v1

master
Michael Hope 4 years ago
parent 5fd0345df8
commit 018f224745

@ -1,8 +1,5 @@
SRC = $(wildcard *.py)
run:
ampy -p /dev/ttyUSB? run clock.py
put: $(SRC:%.py=put-%.stamp)
ampy -p /dev/ttyUSB? ls

@ -1,7 +1,10 @@
import time
import wordclock
def main():
time.sleep(1)
wordclock.main()

@ -0,0 +1,11 @@
def show_stdout(f: Frame):
out = '\033\143'
stride = 11
dots = '.123456789#'
for y in range(len(f.pixels) // stride):
s = f.pixels[y * stride:(y + 1) * stride]
if y & 1 != 0:
s.reverse()
d = [dots[x * len(dots) // (Frame.Max + 1)] for x in s]
out += ''.join(d) + '\n'
print(out + '\n')

@ -2,126 +2,56 @@ import time
import asynced
import iptime
import machine
import board
import neopixel
import random
RANGES = {
'w': 94,
'seven': 88,
'we': 94,
'cl': 102,
'le': 80,
't': 109,
'qua': 17,
'd': 12,
'ne': 63,
'q': 19,
'ex': 31,
'ar': 16,
'hal': 41,
'ac': 20,
'y': 27,
'k': 99,
'twelve': 93,
'ha': 42,
'es': 62,
'lock': 99,
'pa': 44,
'h': 84,
'quarter': 13,
'aster': 45,
'eleven': 77,
'ns': 106,
'se': 105,
'five': 70,
'pas': 44,
'clock': 99,
'p': 44,
'lo': 101,
'went': 23,
'nes': 62,
'paste': 44,
'ur': 68,
'rte': 14,
'e': 105,
'six': 60,
'st': 46,
'amp': 7,
'three': 55,
'tense': 105,
'our': 67,
'x': 60,
'ten': 107,
'sixth': 58,
'quart': 15,
'eight': 83,
'n': 107,
'v': 97,
'tens': 106,
'l': 102,
'to': 33,
's': 106,
'nine': 51,
'four': 66,
'rd': 12,
'twentyfive': 22,
'art': 15,
'wen': 23,
'vent': 90,
'as': 45,
'er': 48,
'am': 7,
'its': 0,
'halfs': 39,
'oclock': 99,
'vet': 72,
'two': 74,
'eve': 89,
'ty': 26,
're': 56,
'pm': 9,
'o': 101,
'si': 61,
'fs': 39,
'run': 49,
'it': 0,
'even': 89,
'past': 44,
'f': 70,
'm': 10,
'r': 69,
'event': 89,
'a': 45,
'g': 85,
'ru': 49,
'c': 100,
'twenty': 22,
'vex': 30,
'half': 40,
'sis': 2,
'th': 58,
'is': 3,
'al': 41,
'in': 52,
'one': 63,
'i': 86,
'on': 64,
'ni': 51,
'ive': 71,
'u': 68,
'ones': 62,
'sam': 6,
'ts': 1
'dude': 0,
'ok': 5,
'ten': 8,
'seven': 11,
'twelve': 16,
'even': 22,
'eleven': 22,
'eight': 28,
'four': 33,
'five': 37,
'two': 41,
'three': 44,
'six': 49,
'one': 52,
'past': 55,
'run': 60,
'nine': 62,
'to': 66,
'TEN': 69,
'HALF': 73,
'TWENTY': 77,
'TWENTYFIVE': 77,
'FIVE': 83,
'QUARTER': 90,
'A': 98,
'AM': 106,
'PM': 108,
'is': 102,
'it': 99,
'its': 99,
}
MINUTES = ('oclock', 'five past', 'ten past', 'quarter past', 'twenty past',
'twentyfive past', 'half past', 'twentyfive to', 'twenty to',
'quarter to', 'ten to', 'five to')
MINUTES = ('oclock', 'FIVE past', 'TEN past', 'QUARTER past', 'TWENTY past',
'TWENTYFIVE past', 'HALF past', 'TWENTYFIVE to', 'TWENTY to',
'QUARTER to', 'TEN to', 'FIVE to')
HOURS = ('twelve', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
'eight', 'nine', 'ten', 'eleven')
AMPM = ('am', 'pm')
AMPM = ('AM', 'PM')
ITS = ('its', 'it is', 'its dude', 'it is dude', 'its ok', 'it is ok')
COLOUR = (200, 255, 200)
def split(secs: int) -> tuple:
@ -136,6 +66,10 @@ def split(secs: int) -> tuple:
return MINUTES[minute], HOURS[hour], AMPM[ampm]
def to_rgb(i, colour) -> tuple:
return ((i * colour[0]) >> 8, (i * colour[1]) >> 8, (i * colour[2]) >> 8)
class Frame:
Max = 255
@ -161,23 +95,23 @@ def render(words: list) -> Frame:
f = Frame()
for word in words:
for w in word.split():
idx = RANGES[w]
for i in range(len(w)):
f.set(idx + i)
idx = RANGES.get(w, None)
if idx is not None:
for i in range(len(w)):
f.set(idx + i)
else:
print('warning: %s is missing' % w)
return f
def show(f: Frame):
out = '\033\143'
stride = 11
dots = '.123456789#'
for y in range(len(f.pixels) // stride):
s = f.pixels[y * stride:(y + 1) * stride]
if y & 1 != 0:
s.reverse()
d = [dots[x * len(dots) // (Frame.Max + 1)] for x in s]
out += ''.join(d) + '\n'
print(out + '\n')
def prefix() -> tuple:
return (ITS[random.randint(0, len(ITS) - 1)], )
def show(f: Frame, n):
for i, p in enumerate(f.pixels):
n[i] = to_rgb(p, COLOUR)
n.show()
DT = 0.1
@ -211,7 +145,7 @@ def run() -> generator:
if nxt == words:
yield from asynced.delay(1)
continue
dest = render(nxt)
dest = render(prefix() + nxt)
for i in range(steps):
yield src.muldiv(steps - i, steps) + dest.muldiv(i, steps)
words = nxt
@ -237,7 +171,20 @@ def bench() -> generator:
print('%d in %.3f %.3f/1' % (i, elapsed, elapsed / i))
def test():
time.sleep(1)
num = 11 * 10
n = neopixel.NeoPixel(board.GPIO2, num, brightness=0.4, auto_write=False)
while True:
for words in ITS:
f = render([words])
show(f, n)
time.sleep(1)
def main():
num = 11 * 10
n = neopixel.NeoPixel(board.GPIO2, num, brightness=1, auto_write=False)
routines = (run(), blink(), asynced.fps(DT), bench())
while True:
for r in routines:
@ -245,8 +192,4 @@ def main():
if f is None:
continue
elif isinstance(f, Frame):
show(f)
if __name__ == '__main__':
main()
show(f, n)

Loading…
Cancel
Save