adafruit_pybadger

Badge-focused CircuitPython helper library for PyBadge and PyGamer.

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_pybadger.Buttons(b, a, start, select, right, down, up, left)
a

Alias for field number 1

b

Alias for field number 0

down

Alias for field number 5

left

Alias for field number 7

right

Alias for field number 4

select

Alias for field number 3

start

Alias for field number 2

up

Alias for field number 6

class adafruit_pybadger.PyBadger(i2c=None, *, pixels_brightness=1.0)

PyBadger class.

acceleration

Accelerometer data, +/- 2G sensitivity.

auto_dim_display(delay=5.0, movement_threshold=10)

Auto-dim the display when board is not moving.

Parameters:
  • delay (int) – Time in seconds before display auto-dims after movement has ceased.
  • movement_threshold (int) – Threshold required for movement to be considered stopped. Change to increase or decrease sensitivity.
static bitmap_qr(matrix)

The QR code bitmap.

brightness

Display brightness.

button

The buttons on the board.

Example use:


from adafruit_pybadger import PyBadger

pybadger = PyBadger()

while True:
if pybadger.button.a:
print(“Button A”)
elif pybadger.button.b:
print(“Button B”)
elif pybadger.button.start:
print(“Button start”)
elif pybadger.button.select:
print(“Button select”)
joystick

The joystick on the PyGamer.

light

Light sensor data.

pixels

Sequence like object representing the NeoPixels on the board.

play_file(file_name)

Play a .wav file using the onboard speaker.

Parameters:file_name – The name of your .wav file in quotation marks including .wav
play_tone(frequency, duration)

Produce a tone using the speaker. Try changing frequency to change the pitch of the tone.

Parameters:
  • frequency (int) – The frequency of the tone in Hz
  • duration (float) – The duration of the tone in seconds
show_badge(*, background_color=16711680, foreground_color=16777215, background_text_color=16777215, foreground_text_color=0, hello_font=<sphinx.ext.autodoc.importer._MockObject object>, hello_scale=1, hello_string='HELLO', my_name_is_font=<sphinx.ext.autodoc.importer._MockObject object>, my_name_is_scale=1, my_name_is_string='MY NAME IS', name_font=<sphinx.ext.autodoc.importer._MockObject object>, name_scale=1, name_string='Blinka')

Create a “Hello My Name is”-style badge.

Parameters:
  • background_color – The color of the background. Defaults to 0xFF0000.
  • foreground_color – The color of the foreground rectangle. Defaults to 0xFFFFFF.
  • background_text_color – The color of the “HELLO MY NAME IS” text. Defaults to 0xFFFFFF.
  • foreground_text_color – The color of the name text. Defaults to 0x000000.
  • hello_font – The font for the “HELLO” string. Defaults to terminalio.FONT.
  • hello_scale – The size scale of the “HELLO” string. Defaults to 1.
  • hello_string – The first string of the badge. Defaults to “HELLO”.
  • my_name_is_font – The font for the “MY NAME IS” string. Defaults to terminalio.FONT.
  • my_name_is_scale – The size scale of the “MY NAME IS” string. Defaults to 1.
  • my_name_is_string – The second string of the badge. Defaults to “MY NAME IS”.
  • name_font – The font for the name string. Defaults to terminalio.FONT.
  • name_scale – The size scale of the name string. Defaults to 1.
  • name_string – The third string of the badge - change to be your name. Defaults to “Blinka”.
show_business_card(*, image_name=None, name_string=None, name_scale=1, name_font=<sphinx.ext.autodoc.importer._MockObject object>, email_string_one=None, email_scale_one=1, email_font_one=<sphinx.ext.autodoc.importer._MockObject object>, email_string_two=None, email_scale_two=1, email_font_two=<sphinx.ext.autodoc.importer._MockObject object>)

Display a bitmap image and a text string, such as a personal image and email address.

Parameters:
  • image_name (str) – REQUIRED. The name of the bitmap image including .bmp, e.g. "Blinka.bmp".
  • name_string (str) – A name string to display along the bottom of the display, e.g. "Blinka".
  • name_scale (int) – The scale of name_string. Defaults to 1.
  • name_font – The font for the name string. Defaults to terminalio.FONT.
  • email_string_one (str) – A string to display along the bottom of the display, e.g. "blinka@adafruit.com".
  • email_scale_one (int) – The scale of email_string_one. Defaults to 1.
  • email_font_one – The font for the first email string. Defaults to terminalio.FONT.
  • email_string_two (str) – A second string to display along the bottom of the display. Use if your email address is longer than one line or to add more space between the name and email address, e.g. (blinka@) "adafruit.com".
  • email_scale_two (int) – The scale of email_string_two. Defaults to 1.
  • email_font_two – The font for the second email string. Defaults to terminalio.FONT.
show_qr_code(*, data='https://circuitpython.org')

Generate a QR code and display it for dwell seconds.

Parameters:
  • data (string) – A string of data for the QR code
  • dwell (int) – The amount of time in seconds to display the QR code
show_terminal()

Revert to terminalio screen.

start_tone(frequency)

Produce a tone using the speaker. Try changing frequency to change the pitch of the tone.

Parameters:frequency (int) – The frequency of the tone in Hz
stop_tone()

Use with start_tone to stop the tone produced.

adafruit_pybadger.load_font(fontname, text)

Load a font and glyphs in the text string

Parameters:
  • fontname (str) – The full path to the font file.
  • text (str) – The text containing the glyphs we want to load.