Skip to content

Instantly share code, notes, and snippets.

@j4ckofalltrades
Last active July 14, 2023 11:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Using the Badger2040 as a digital lanyard / badge - https://jduabe.dev/posts/2023/programmable-badge/
# Using the Badger2040 as a digital badge / lanyard
import badger2040
WIDTH = badger2040.WIDTH # 296
HEIGHT = badger2040.HEIGHT # 128
BANNER_HEIGHT = 30
BANNER_TEXT_SIZE = 0.8
NAME_PADDING_LEFT = 60
# badge contents
BANNER = "Random Event"
NAME = "First Name"
HANDLE = "@handle"
display = badger2040.Badger2040()
# draw banner
display.set_pen(15)
display.set_font("serif")
display.text(BANNER, 20, (BANNER_HEIGHT // 2) + 1, WIDTH, BANNER_TEXT_SIZE)
display.rectangle(1, BANNER_HEIGHT + 1, WIDTH + 1, HEIGHT - BANNER_HEIGHT)
# draw name
display.set_pen(0)
display.set_thickness(2)
display.set_font("sans")
display.text(NAME, NAME_PADDING_LEFT, HEIGHT - 60, WIDTH, 1.7)
display.text(HANDLE, NAME_PADDING_LEFT, HEIGHT - 20, WIDTH, 0.7)
# draw border enclosing banner and name
display.set_thickness(5)
display.line(WIDTH, 0, WIDTH - 1, HEIGHT)
display.line(0, HEIGHT, WIDTH - 1, HEIGHT - 1)
display.update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment