|
| 1 | +# SPDX-FileCopyrightText: 2022 Jeff Epler for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +# pylint: disable=consider-using-with |
| 5 | + |
| 6 | +import asyncio |
| 7 | +from displayio import TileGrid, OnDiskBitmap, Group |
| 8 | +from rainbowio import colorwheel |
| 9 | +from adafruit_pybadger import pybadger |
| 10 | + |
| 11 | +# If you choose to enter a pronoun it's shown on the "business card" page |
| 12 | +pronoun = "" |
| 13 | +custom_line1 = "FIRST" |
| 14 | +custom_line2 = "LAST" # also a great place to show a pronoun |
| 15 | + |
| 16 | +# Set up the custom image |
| 17 | +qr_image = OnDiskBitmap(open("/QR_Blinka_CircuitPythonOrg.bmp", "rb")) |
| 18 | +qr_tg = TileGrid(qr_image, pixel_shader=qr_image.pixel_shader) |
| 19 | +qr_gp = Group() |
| 20 | +qr_gp.append(qr_tg) |
| 21 | + |
| 22 | +pybadger.badge_background( |
| 23 | + background_color=pybadger.WHITE, |
| 24 | + rectangle_color=pybadger.PURPLE, |
| 25 | + rectangle_drop=0.25, |
| 26 | + rectangle_height=0.55, |
| 27 | +) |
| 28 | + |
| 29 | +pybadger.badge_line( |
| 30 | + text="HELLO I'M", color=pybadger.BLINKA_PURPLE, scale=2, padding_above=1 |
| 31 | +) |
| 32 | +pybadger.badge_line(text=custom_line1, color=pybadger.WHITE, scale=6, padding_above=1) |
| 33 | +pybadger.badge_line( |
| 34 | + text=custom_line2, color=pybadger.BLINKA_PURPLE, scale=2, padding_above=0.25 |
| 35 | +) |
| 36 | + |
| 37 | +# Start with the custom badge page |
| 38 | +pybadger.show_custom_badge() |
| 39 | + |
| 40 | +# This task responds to buttons and changes the visible page |
| 41 | +async def ui_task(): |
| 42 | + while True: |
| 43 | + if pybadger.button.a: |
| 44 | + pybadger.show_business_card( |
| 45 | + image_name="Blinka.bmp", |
| 46 | + name_string="Jeff Epler", |
| 47 | + name_scale=2, |
| 48 | + email_string_one="[email protected]", |
| 49 | + email_string_two=pronoun, |
| 50 | + ) |
| 51 | + elif pybadger.button.b: |
| 52 | + pybadger.show(qr_gp) |
| 53 | + elif pybadger.button.start: |
| 54 | + pybadger.show_custom_badge() |
| 55 | + elif pybadger.button.select: |
| 56 | + pybadger.activity() |
| 57 | + else: |
| 58 | + pybadger.auto_dim_display( |
| 59 | + delay=0.5 |
| 60 | + ) # Remove or comment out this line if you have the PyBadge LC |
| 61 | + await asyncio.sleep(0.02) |
| 62 | + |
| 63 | + |
| 64 | +# This task animates the LEDs |
| 65 | +async def led_task(): |
| 66 | + pixels = pybadger.pixels |
| 67 | + pixels.auto_write = False |
| 68 | + num_pixels = len(pixels) |
| 69 | + j = 0 |
| 70 | + while True: |
| 71 | + bright = pybadger.display.brightness > 0.5 |
| 72 | + j = (j + (7 if bright else 3)) & 255 |
| 73 | + b = 31 / 255.0 if bright else 5 / 255.0 |
| 74 | + if pixels.brightness != b: |
| 75 | + pixels.brightness = b |
| 76 | + for i in range(num_pixels): |
| 77 | + rc_index = i * 97 + j |
| 78 | + pixels[i] = colorwheel(rc_index & 255) |
| 79 | + pixels.show() |
| 80 | + await asyncio.sleep(0.02) |
| 81 | + |
| 82 | + |
| 83 | +# Run both tasks via asyncio! |
| 84 | +async def main(): |
| 85 | + await asyncio.gather(ui_task(), led_task()) |
| 86 | + |
| 87 | + |
| 88 | +asyncio.run(main()) |
0 commit comments