from adafruit_pybadger import pybadger
Now you have access to all the features PyBadger has to offer, including badge, business card, and QR code creation.
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
To change the badge to display your name, set name_string="Your Name"
when you create the badge object.
Each of the scales applies to a different line on the badge, e.g. hello_scale
applies to the HELLO string on the badge. When using the default font, the above values for hello_scale
and my_name_is_scale
are ideal. Depending on the length of your name, you'll want to tweak name_scale
to allow it to fit properly.
Auto-Dim the Display
The display is the part of the badge that uses up the most battery. To help mitigate that, PyBadger includes the ability to auto-dim the display if the badge isn't moving. If you set it down somewhere, it'll use less battery.
while True: pybadger.auto_dim_display()
It defaults to dimming after 5
seconds, and brightening up again on a fairly small movement threshold of 1.5
. If you would like to change either of those, you can do so when adding the auto_dim_display()
function to your code. For example, to change it to wait 10 seconds before dimming, and require more movement to brighten up again, you would add the following:
pybadger.auto_dim_display(delay=10, movement_threshold=20)
The higher the movement_threshold
, the more movement it takes to cause the display to return to full brightness.
Business Card
Everyone exchanges business cards at conferences. But it means carrying extra things around and trying to remember who gave you the card in the first place. Not any more! Now you can display a simple business card with your picture, name, and email address. Someone can snap a quick picture of it, and have your face and info available for later.
Blinka wants to display her name, email and image when pressing button A.
if pybadger.button.a: pybadger.show_business_card(image_name="Blinka.bmp", name_string="Blinka", name_scale=2, email_string_one="blinka@", email_string_two="adafruit.com")
The show_business_card
function requires you to provide a bitmap image name as a string. You can optionally add your name as a string, and up to two lines of an email address (or any other info you'd like to provide!).
The badge will continue to display the business card until you tell it to display something else by pressing another button.
Images must be in 16-bit or 24-bit BMP format, and ideally 160x128 pixels. Here's the blinka.bmp file if you need to see what the format is:
QR Code
Blinka wants to direct other conference attendees to her website. She can easily do that by generating a QR code and having it display when pressing button B.
elif pybadger.button.b: pybadger.show_qr_code(data="https://circuitpython.org")
The show_qr_code
function allows you to set its target by setting data=
a string with the target info in it. For example, Blinka wants to point to circuitpython.org and so she sets data="https://circuitpython.org"
.
The badge will continue to display the QR code until you tell it to display something else by pressing another button.
Return to Hello My Name Is...
Blinka needs a way to display the Hello My Name Is part of the badge again after showing off her business card and QR code. So the last thing included is assigning the start button to display it.
elif pybadger.button.start: pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
That's all there is to creating a fun, interactive conference or event badge!
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT from adafruit_pybadger import pybadger pybadger.show_badge( name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3 ) while True: pybadger.auto_dim_display( delay=10 ) # Remove or comment out this line if you have the PyBadge LC if pybadger.button.a: pybadger.show_business_card( image_name="Blinka.bmp", name_string="Blinka", name_scale=2, email_string_one="blinka@", email_string_two="adafruit.com", ) elif pybadger.button.b: pybadger.show_qr_code(data="https://circuitpython.org") elif pybadger.button.start: pybadger.show_badge( name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3 )
Text editor powered by tinymce.