Created
May 4, 2019 11:41
-
-
Save seantibor/9c7399d4451b8bae01cfbe7695eb3829 to your computer and use it in GitHub Desktop.
PyPortal conference badge for #PyCon2019
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
""" | |
This example will set up a simple conference badge with two different screens and a QR code. | |
""" | |
import time | |
import board | |
from adafruit_pyportal import PyPortal | |
import adafruit_touchscreen | |
# the current working directory (where this file is) | |
cwd = ("/"+__file__).rsplit('/', 1)[0] | |
# Initialize the pyportal object and let us know what data to fetch and where | |
# to display it | |
images = [('/pinecrest_badge.bmp', b'http://bit.ly/2vEzT8e'), | |
('/tp_chalkboard.bmp', b'http://bit.ly/2VBx8mL')] | |
pyportal = PyPortal( | |
status_neopixel=board.NEOPIXEL, | |
default_bg=cwd+"/pinecrest_badge.bmp", | |
text_font=cwd+"/fonts/Collegiate-50.bdf", | |
text_position=(175, 185), | |
text_color=0xFFFFFF, | |
caption_font=cwd+"/fonts/Collegiate-24.bdf", | |
caption_position=(30, 220), | |
caption_color=0xFFFFFF,) | |
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, | |
board.TOUCH_YD, board.TOUCH_YU, | |
calibration=((5200, 59000), (5800, 57000)), | |
size=(320, 240)) | |
current_image = 0 | |
backlight = True | |
backlight_timeout_seconds = 120 | |
backlight_timeout = True | |
light_on_time = time.monotonic() | |
def qr_popup(url, duration=30, touch_escape=True): | |
pyportal.show_QR(url, qr_size=8, x=54, y=20) | |
start_time = time.monotonic() | |
while True: | |
touched = ts.touch_point if touch_escape else False | |
if time.monotonic() - start_time > duration or touched: | |
print('returning') | |
pyportal._qr_group.pop() | |
board.DISPLAY.show(pyportal.splash) | |
return | |
while True: | |
p = ts.touch_point | |
if p: | |
print('{} was pressed'.format(p)) | |
light_on_time = time.monotonic() | |
if not backlight: | |
backlight = 1.0 | |
pyportal.set_backlight(1.0) | |
elif p[0] > 260 and p[1] < 64: | |
backlight_timeout = not backlight_timeout | |
print('toggling backlight timout') | |
if not backlight_timeout: | |
pyportal.neo_status((0,255,255)) | |
else: | |
pyportal.neo_status((0,0,0)) | |
time.sleep(0.5) #prevent bounce | |
elif p[1] < 240//3 * 2: | |
current_image += 1 | |
if current_image == len(images): | |
current_image = 0 | |
pyportal.set_background(cwd+images[current_image][0]) | |
else: | |
qr_popup(images[current_image][1]) | |
if backlight_timeout and backlight and (time.monotonic() - light_on_time) > backlight_timeout_seconds: | |
backlight = False | |
pyportal.set_backlight(0) | |
time.sleep(0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment