I recently purchased an Adafruit PyBadge LC. and I’ve had a lot fun tinkering around with it. There are three boards in this family of boards from Adafruit:
- PyBadge LC (the one I have)
- PyBadge
- PyGamer
The PyBadge LC is the cheapest of the bunch, hence the LC for low cost. For more details on the differences between the boards check out Adafruit’s comparison guide here.
Each board supports programming with Arduino, CircuitPython, and MakeCode Arcade. I love Python and this has been a great opportunity to learn how to use CircuitPython.
Adafruit PyBadge Projects
This blog post will serve as an place for me to document some of my PyBadge projects. I also create a repo on GitHub to store my code.py files.
Conference Badge
Adafruit has a Learning Guide on how to make a conference badge with the PyBadge. I loaded the CircuitPython script onto my PyBadge with a few modifications of my own.
I updated the main loop to handle user input from the start and select buttons. When the buttons are pressed the conference badge’s background color updates.
Here are the modified excerpts. The full script is on GitHub.
First I created a list of colors.
VIOLET = 0x9400D3
INDIGO = 0x4B0082
BLUE = 0x0000FF
GREEN = 0x00FF00
YELLOW = 0xFFFF00
ORANGE = 0xFF7F00
RED = 0xFF0000
RAINBOW_COLORS = [VIOLET, INDIGO, BLUE, GREEN, YELLOW, ORANGE, RED]
Then I modified the main loop to reference the RAINBOW_COLORS list when the user clicks on the start or select buttons.
current_buttons = pad.get_pressed()
last_read = 0
color_index = 0
while True:
for color in range(0, 360, speed):
# omitting other code
if current_buttons != buttons:
# Respond to the buttons
if (buttons & BUTTON_START):
if color_index + 1 == len(RAINBOW_COLORS):
color_index = 0
else:
color_index += 1
splash[0].pixel_shader[0] = RAINBOW_COLORS[color_index]
elif (buttons & BUTTON_SEL):
if color_index - 1 == -1:
color_index = len(RAINBOW_COLORS) - 1
else:
color_index -= 1
splash[0].pixel_shader[0] = RAINBOW_COLORS[color_index]
current_buttons = buttons
Animating a Sprite with Adafruit’s PyBadge
My next PyBadge project was a simple CircuitPython script that loaded a sprite sheet and animated it. When Michael and I first started this blog I whipped up a pair of sprites of our likeness for branding. I decided to take my sprite to the next level with a sprite sheet. I used the online pixel editor, Piskel, to create the art.
I used Adafruit’s Learning Guide on CircuitPython Display Support using displayio as a starting point for this small project. Full code for my PyBadge script is on GitHub.
What’s Next?
I have a few more skill builder projects that I would like to tackle and then I’ll be ready to implement a couple of cool projects I thought of for the PyBadge.