-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathledmatrix.py
More file actions
94 lines (81 loc) · 2.55 KB
/
Copy pathledmatrix.py
File metadata and controls
94 lines (81 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from datetime import datetime, timedelta
import time
import random
from inputmodule.gui.gui_threading import (
reset_thread,
is_thread_stopped,
is_dev_disconnected,
set_status,
get_status,
)
from inputmodule.inputmodule.ledmatrix import (
light_leds,
show_string,
eq,
breathing,
animate,
)
from inputmodule.inputmodule import brightness
def countdown(dev, seconds):
"""Run a countdown timer. Lighting more LEDs every 100th of a seconds.
Until the timer runs out and every LED is lit"""
animate(dev, False)
set_status('countdown')
start = datetime.now()
target = seconds * 1_000_000
while get_status() == 'countdown':
if is_thread_stopped() or is_dev_disconnected(dev.device):
reset_thread()
return
now = datetime.now()
passed_time = (now - start) / timedelta(microseconds=1)
ratio = passed_time / target
if passed_time >= target:
break
leds = int(306 * ratio)
light_leds(dev, leds)
time.sleep(0.01)
if get_status() == 'countdown':
light_leds(dev, 306)
breathing(dev)
# blinking(dev)
def blinking(dev):
"""Blink brightness high/off every second.
Keeps currently displayed grid"""
set_status('blinking')
while get_status() == 'blinking':
if is_thread_stopped() or is_dev_disconnected(dev.device):
reset_thread()
return
brightness(dev, 0)
time.sleep(0.5)
brightness(dev, 200)
time.sleep(0.5)
def random_eq(dev):
"""Display an equlizer looking animation with random values."""
animate(dev, False)
set_status('random_eq')
while get_status() == 'random_eq':
if is_thread_stopped() or is_dev_disconnected(dev.device):
reset_thread()
return
# Lower values more likely, makes it look nicer
weights = [i * i for i in range(33, 0, -1)]
population = list(range(1, 34))
vals = random.choices(population, weights=weights, k=9)
eq(dev, vals)
time.sleep(0.2)
def clock(dev):
"""Render the current time and display.
Loops forever, updating every second"""
animate(dev, False)
set_status('clock')
while get_status() == 'clock':
if is_thread_stopped() or is_dev_disconnected(dev.device):
reset_thread()
return
now = datetime.now()
current_time = now.strftime("%H:%M")
print("Current Time =", current_time)
show_string(dev, current_time)
time.sleep(1)