Skip to content

Instantly share code, notes, and snippets.

@j4ckofalltrades
Last active July 14, 2023 11:38
Show Gist options
  • Save j4ckofalltrades/a4ec95b3e077fd7c294d20ef8095f480 to your computer and use it in GitHub Desktop.
Save j4ckofalltrades/a4ec95b3e077fd7c294d20ef8095f480 to your computer and use it in GitHub Desktop.
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