Skip to content

Commit a36613e

Browse files
authored
Merge branch 'master' into master
2 parents 0020969 + 0a50b16 commit a36613e

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

BusyBox_Sign/code.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import time
2+
import board
3+
import neopixel
4+
from adafruit_led_animation.animation.comet import Comet
5+
from adafruit_led_animation.animation.pulse import Pulse
6+
from adafruit_led_animation.animation.blink import Blink
7+
from adafruit_led_animation.animation.rainbow import Rainbow
8+
from adafruit_led_animation.animation.colorcycle import ColorCycle
9+
from adafruit_led_animation.sequence import AnimationSequence
10+
from adafruit_led_animation import helper
11+
from adafruit_led_animation.color import PURPLE, AQUA, RED, JADE, ORANGE, YELLOW, BLUE
12+
13+
#Setup NeoPixels
14+
pixel_pin = board.D6
15+
pixel_num = 16
16+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=.9, auto_write=False)
17+
18+
#Setup NeoPixel Grid
19+
pixel_wing_vertical = helper.PixelMap.vertical_lines(
20+
pixels, 8, 2, helper.horizontal_strip_gridmap(8, alternating=True)
21+
)
22+
pixel_wing_horizontal = helper.PixelMap.horizontal_lines(
23+
pixels, 8, 2, helper.horizontal_strip_gridmap(8, alternating=True)
24+
)
25+
26+
#Setup LED Animations
27+
rainbow = Rainbow(pixels, speed=.001, period=2)
28+
pulse = Pulse(pixels, speed=0.1, color=RED, period=3)
29+
blink = Blink(pixels, speed=0.5, color=RED)
30+
colorcycle = ColorCycle(pixels, speed=0.4, colors=[RED, ORANGE, YELLOW, JADE, BLUE, AQUA, PURPLE])
31+
comet_v = Comet(pixel_wing_vertical, speed=0.05, color=PURPLE, tail_length=6, bounce=True)
32+
33+
#Setup the LED Sequences
34+
animations = AnimationSequence(
35+
rainbow,
36+
pulse,
37+
comet_v,
38+
blink,
39+
colorcycle,
40+
advance_interval=5.95,
41+
)
42+
43+
#Run ze animations!
44+
while True:
45+
animations.animate()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Quote board matrix display
2+
# uses AdafruitIO to serve up a quote text feed and color feed
3+
# random quotes are displayed, updates periodically to look for new quotes
4+
# avoids repeating the same quote twice in a row
5+
6+
import time
7+
import random
8+
import board
9+
import terminalio
10+
from adafruit_matrixportal.matrixportal import MatrixPortal
11+
12+
# --- Display setup ---
13+
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True)
14+
15+
# Create a new label with the color and text selected
16+
matrixportal.add_text(
17+
text_font=terminalio.FONT,
18+
text_position=(0, (matrixportal.graphics.display.height // 2) - 1),
19+
scrolling=True,
20+
)
21+
22+
# Static 'Connecting' Text
23+
matrixportal.add_text(
24+
text_font=terminalio.FONT,
25+
text_position=(2, (matrixportal.graphics.display.height // 2) - 1),
26+
)
27+
28+
QUOTES_FEED = "sign-quotes.signtext"
29+
COLORS_FEED = "sign-quotes.signcolor"
30+
SCROLL_DELAY = 0.02
31+
UPDATE_DELAY = 600
32+
33+
quotes = []
34+
colors = []
35+
last_color = None
36+
last_quote = None
37+
38+
39+
def update_data():
40+
print("Updating data from Adafruit IO")
41+
matrixportal.set_text("Connecting", 1)
42+
43+
try:
44+
quotes_data = matrixportal.get_io_data(QUOTES_FEED)
45+
quotes.clear()
46+
for json_data in quotes_data:
47+
quotes.append(matrixportal.network.json_traverse(json_data, ["value"]))
48+
print(quotes)
49+
# pylint: disable=broad-except
50+
except Exception as error:
51+
print(error)
52+
53+
try:
54+
color_data = matrixportal.get_io_data(COLORS_FEED)
55+
colors.clear()
56+
for json_data in color_data:
57+
colors.append(matrixportal.network.json_traverse(json_data, ["value"]))
58+
print(colors)
59+
# pylint: disable=broad-except
60+
except Exception as error:
61+
print(error)
62+
63+
if not quotes or not colors:
64+
raise "Please add at least one quote and color to your feeds"
65+
matrixportal.set_text(" ", 1)
66+
67+
68+
update_data()
69+
last_update = time.monotonic()
70+
matrixportal.set_text(" ", 1)
71+
quote_index = None
72+
color_index = None
73+
74+
while True:
75+
# Choose a random quote from quotes
76+
if len(quotes) > 1 and last_quote is not None:
77+
while quote_index == last_quote:
78+
quote_index = random.randrange(0, len(quotes))
79+
else:
80+
quote_index = random.randrange(0, len(quotes))
81+
last_quote = quote_index
82+
83+
# Choose a random color from colors
84+
if len(colors) > 1 and last_color is not None:
85+
while color_index == last_color:
86+
color_index = random.randrange(0, len(colors))
87+
else:
88+
color_index = random.randrange(0, len(colors))
89+
last_color = color_index
90+
91+
# Set the quote text
92+
matrixportal.set_text(quotes[quote_index])
93+
94+
# Set the text color
95+
matrixportal.set_text_color(colors[color_index])
96+
97+
# Scroll it
98+
matrixportal.scroll_text(SCROLL_DELAY)
99+
100+
if time.monotonic() > last_update + UPDATE_DELAY:
101+
update_data()
102+
last_update = time.monotonic()

0 commit comments

Comments
 (0)