Skip to content

Commit c7a39e4

Browse files
committed
Code for Matrix Portal Handbag
first commit
1 parent 7c2f8e2 commit c7a39e4

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

Matrix_Portal_Handbag/code.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
"""
2+
Slideshow Example using the Matrix Portal and 64 x 32 LED matrix display
3+
Written by Melissa LeBlanc-Williams and Erin St Blaine for Adafruit Industries
4+
Images smaller than 64 pixel width will be aligned alternating left or right
5+
Press Up button to pause/resume Slideshow
6+
Press Down button to cycle between slideshow folders
7+
"""
8+
import time
9+
import board
10+
import adafruit_lis3dh
11+
import displayio
12+
import busio
13+
from digitalio import DigitalInOut, Pull
14+
from adafruit_matrixportal.matrix import Matrix
15+
from adafruit_slideshow import SlideShow, HorizontalAlignment
16+
from adafruit_debouncer import Debouncer
17+
18+
'''
19+
Display will go to sleep after SLEEP_DURATION seconds have elapsed with no accelerometer movement
20+
Each slide will play for IMAGE_DURATION - customizable for each folder
21+
Add folders to the list to add more slideshows.
22+
'''
23+
24+
SLEEP_DURATION = 60
25+
IMAGE_DURATION = (1, 0.5, 10)
26+
IMAGE_FOLDER = (
27+
"/bmps",
28+
"/bmps2",
29+
"/bmps3",
30+
)
31+
# pylint: disable=invalid-name
32+
# --- Display setup ---
33+
matrix = Matrix(bit_depth=6)
34+
display = matrix.display
35+
ACCEL = adafruit_lis3dh.LIS3DH_I2C(busio.I2C(board.SCL, board.SDA),
36+
address=0x19)
37+
_ = ACCEL.acceleration # Dummy reading to blow out any startup residue
38+
39+
pin_down = DigitalInOut(board.BUTTON_DOWN)
40+
pin_down.switch_to_input(pull=Pull.UP)
41+
button_down = Debouncer(pin_down)
42+
pin_up = DigitalInOut(board.BUTTON_UP)
43+
pin_up.switch_to_input(pull=Pull.UP)
44+
button_up = Debouncer(pin_up)
45+
46+
ALIGN_RIGHT = True
47+
auto_advance = True
48+
49+
i = 0
50+
NUM_FOLDERS = 2 #first folder is numbered 0
51+
52+
slideshow = SlideShow(
53+
display,
54+
None,
55+
folder=IMAGE_FOLDER[i],
56+
order=0,
57+
auto_advance=False,
58+
fade_effect=False,
59+
dwell=IMAGE_DURATION[i],
60+
h_align=HorizontalAlignment.RIGHT,
61+
)
62+
63+
LAST_ADVANCE = time.monotonic()
64+
last_movement = time.monotonic()
65+
MODE = 1
66+
67+
def advance():
68+
''' go to the next slide '''
69+
# pylint: disable=global-statement
70+
global ALIGN_RIGHT, LAST_ADVANCE
71+
ALIGN_RIGHT = not ALIGN_RIGHT
72+
if ALIGN_RIGHT:
73+
slideshow.h_align = HorizontalAlignment.RIGHT
74+
else:
75+
slideshow.h_align = HorizontalAlignment.LEFT
76+
LAST_ADVANCE = time.monotonic()
77+
slideshow.advance()
78+
79+
empty_group = displayio.Group()
80+
81+
while True:
82+
if ACCEL.shake(shake_threshold=10):
83+
print("Moving!")
84+
if MODE == 0:
85+
slideshow = SlideShow(
86+
display,
87+
None,
88+
folder=IMAGE_FOLDER[i],
89+
order=0,
90+
auto_advance=False,
91+
fade_effect=False,
92+
dwell=IMAGE_DURATION[i],
93+
h_align=HorizontalAlignment.RIGHT,
94+
)
95+
last_movement = time.monotonic()
96+
MODE = 1
97+
elif time.monotonic() > last_movement + SLEEP_DURATION:
98+
MODE = 0
99+
display.show(empty_group)
100+
if MODE == 1:
101+
if auto_advance and time.monotonic() > LAST_ADVANCE + IMAGE_DURATION[i]:
102+
advance()
103+
button_down.update()
104+
button_up.update()
105+
if button_up.fell:
106+
auto_advance = not auto_advance
107+
if button_down.fell:
108+
i = i + 1
109+
if i > NUM_FOLDERS:
110+
i = 0
111+
slideshow = SlideShow(
112+
display,
113+
None,
114+
folder=IMAGE_FOLDER[i],
115+
order=0,
116+
auto_advance=False,
117+
fade_effect=False,
118+
dwell=IMAGE_DURATION[i],
119+
h_align=HorizontalAlignment.RIGHT,
120+
)

0 commit comments

Comments
 (0)