|
| 1 | +""" |
| 2 | +Slideshow Example using the Matrix Portal and 64 x 32 LED matrix display |
| 3 | +Written by Melissa LeBlanc-Williams 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 advance |
| 7 | +""" |
| 8 | +import time |
| 9 | +import board |
| 10 | +from digitalio import DigitalInOut, Pull |
| 11 | +from adafruit_matrixportal.matrix import Matrix |
| 12 | +from adafruit_slideshow import SlideShow, PlayBackDirection, HorizontalAlignment |
| 13 | +from adafruit_debouncer import Debouncer |
| 14 | + |
| 15 | +IMAGE_DURATION = 3 |
| 16 | +IMAGE_FOLDER = "/bmps" |
| 17 | + |
| 18 | +# --- Display setup --- |
| 19 | +matrix = Matrix(bit_depth=6) |
| 20 | +display = matrix.display |
| 21 | + |
| 22 | +pin_down = DigitalInOut(board.BUTTON_DOWN) |
| 23 | +pin_down.switch_to_input(pull=Pull.UP) |
| 24 | +button_down = Debouncer(pin_down) |
| 25 | +pin_up = DigitalInOut(board.BUTTON_UP) |
| 26 | +pin_up.switch_to_input(pull=Pull.UP) |
| 27 | +button_up = Debouncer(pin_up) |
| 28 | + |
| 29 | +align_right = True |
| 30 | +auto_advance = True |
| 31 | + |
| 32 | +slideshow = SlideShow( |
| 33 | + display, |
| 34 | + None, |
| 35 | + folder=IMAGE_FOLDER, |
| 36 | + order=0, |
| 37 | + auto_advance=False, |
| 38 | + fade_effect=False, |
| 39 | + dwell=IMAGE_DURATION, |
| 40 | + h_align=HorizontalAlignment.RIGHT, |
| 41 | +) |
| 42 | +last_advance = time.monotonic() |
| 43 | + |
| 44 | + |
| 45 | +def advance(): |
| 46 | + # pylint: disable=global-statement |
| 47 | + global align_right, last_advance |
| 48 | + align_right = not align_right |
| 49 | + if align_right: |
| 50 | + slideshow.h_align = HorizontalAlignment.RIGHT |
| 51 | + else: |
| 52 | + slideshow.h_align = HorizontalAlignment.LEFT |
| 53 | + last_advance = time.monotonic() |
| 54 | + slideshow.advance() |
| 55 | + |
| 56 | + |
| 57 | +while True: |
| 58 | + if auto_advance and time.monotonic() > last_advance + IMAGE_DURATION: |
| 59 | + advance() |
| 60 | + button_down.update() |
| 61 | + button_up.update() |
| 62 | + if button_up.fell: |
| 63 | + auto_advance = not auto_advance |
| 64 | + if button_down.fell: |
| 65 | + slideshow.direction = PlayBackDirection.FORWARD |
| 66 | + advance() |
0 commit comments