Created
May 31, 2019 11:00
-
-
Save lesp/4d050388cd7e59276f96b968cc2a99fa to your computer and use it in GitHub Desktop.
PyPortal Digital Conference Badge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
from adafruit_pyportal import PyPortal | |
from adafruit_button import Button | |
from adafruit_slideshow import PlayBackOrder, SlideShow, PlayBackDirection | |
# Set the background color | |
BACKGROUND_COLOR = 0x000000 | |
# Setup PyPortal without networking | |
pyportal = PyPortal(default_bg=BACKGROUND_COLOR) | |
spots = [ | |
{'label': "1", 'pos': (10, 10), 'size': (140, 220), 'color': (255,0,0)}, | |
{'label': "2", 'pos': (160, 10), 'size': (140, 220), 'color': (0,255,0)} | |
] | |
buttons = [] | |
for spot in spots: | |
button = Button(x=spot['pos'][0], y=spot['pos'][1], | |
width=spot['size'][0], height=spot['size'][1], | |
style=Button.SHADOWROUNDRECT, | |
fill_color=spot['color'], outline_color=0x222222, | |
name=spot['label']) | |
pyportal.splash.append(button.group) | |
buttons.append(button) | |
mode = 0 | |
slideshow = SlideShow(board.DISPLAY, folder="/", | |
loop=True, order=PlayBackOrder.ALPHABETICAL, dwell=0, fade_effect=True, auto_advance=False) | |
while True: | |
touch = pyportal.touchscreen.touch_point | |
if touch: | |
for button in buttons: | |
if button.contains(touch): | |
print("Touched", button.name) | |
if mode == 0: | |
print("FORWARD") | |
slideshow.direction = PlayBackDirection.FORWARD | |
slideshow.advance() | |
elif mode == 1: | |
print("REVERSE") | |
slideshow.direction = PlayBackDirection.BACKWARD | |
slideshow.advance() | |
break | |
time.sleep(0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment