Last active
November 20, 2019 03:19
-
-
Save unwiredben/5a96c8828135688082df5e3b86514841 to your computer and use it in GitHub Desktop.
edited code.py from Ben's supercon 2019 alt 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
from adafruit_pybadger import PyBadger | |
import time | |
pybadger = PyBadger() | |
pybadger.auto_dim_display(delay=10) | |
first_display = True | |
rainbow = [ | |
(0x10, 0x00, 0x00), | |
(0x10, 0x10, 0x00), | |
(0x00, 0x10, 0x00), | |
(0x00, 0x00, 0x10), | |
(0x10, 0x00, 0x10) | |
] | |
def iterateRainbow(): | |
global rainbow | |
global brightness | |
for i in range(len(rainbow)): | |
pybadger.pixels[i] = rainbow[i] | |
pybadger.pixels.brightness = brightness | |
pybadger.pixels.show() | |
first = rainbow[0] | |
rainbow = rainbow[1:] | |
rainbow.append(first) | |
nextAnimationTime = 0 | |
brightness = 0.3 | |
animationSpeed = 0.7 | |
oldDown = False | |
oldUp = False | |
oldLeft = False | |
oldRight = False | |
while True: | |
if pybadger.button.a or first_display: | |
pybadger.show_business_card(image_name="unwiredben_profile.bmp", name_string="Ben Combee", name_scale=1, | |
email_string_one="[email protected]", | |
email_string_two="https://www.combee.net/") | |
elif pybadger.button.b: | |
pybadger.show_qr_code(data="https://combee.net/") | |
elif not oldUp and pybadger.button.up: | |
brightness = min(brightness + 0.1, 1) | |
elif not oldDown and pybadger.button.down: | |
brightness = max(brightness - 0.1, 0) | |
elif not oldLeft and pybadger.button.left: | |
animationSpeed = min(animationSpeed + 0.1, 1) | |
elif not oldRight and pybadger.button.right: | |
animationSpeed = max(animationSpeed - 0.1, 0.1) | |
elif pybadger.button.start: | |
pybadger.show_badge( | |
background_color=(102 * 65536 + 45 * 256 + 145), | |
name_string="unwiredben", name_scale=2, | |
hello_scale=2, hello_string="HOWDY, I'M", | |
my_name_is_scale=2, my_name_is_string="(he/him/his)") | |
first_display = False | |
oldDown = pybadger.button.down | |
oldUp = pybadger.button.up | |
oldLeft = pybadger.button.left | |
oldRight = pybadger.button.right | |
if time.monotonic() > nextAnimationTime: | |
iterateRainbow() | |
nextAnimationTime = time.monotonic() + animationSpeed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment