Skip to content

Commit f8bcb20

Browse files
committed
working on magtag and example
1 parent c61bc37 commit f8bcb20

File tree

4 files changed

+109
-5
lines changed

4 files changed

+109
-5
lines changed

adafruit_pybadger/mag_tag.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
`adafruit_pybadger.clue`
2424
================================================================================
2525
26-
Badge-focused CircuitPython helper library for CLUE.
26+
Badge-focused CircuitPython helper library for Mag Tag.
2727
2828
2929
* Author(s): Kattni Rembor, Tim C
@@ -33,7 +33,7 @@
3333
3434
**Hardware:**
3535
36-
* `Adafruit CLUE <https://www.adafruit.com/product/4500>`_
36+
* `Adafruit Mag Tag <https://www.adafruit.com/product/4800>`_
3737
3838
**Software and Dependencies:**
3939
@@ -44,8 +44,9 @@
4444

4545
from collections import namedtuple
4646
import board
47-
import digitalio
48-
from gamepad import GamePad
47+
48+
# import digitalio
49+
# from gamepad import GamePad
4950
import neopixel
5051
from adafruit_pybadger.pybadger_base import PyBadgerBase
5152

@@ -91,7 +92,6 @@ def button(self):
9192
elif pybadger.button.b:
9293
print("Button B")
9394
"""
94-
pass
9595
# button_values = self._buttons.get_pressed()
9696
# return Buttons(
9797
# button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A,

examples/Blinka_MagTag.bmp

38.1 KB
Binary file not shown.

examples/Blinka_MagTag.bmp.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: BLINKA is a registered trademark of Adafruit, LLC. The design is exclusive property of Adafruit, LLC
2+
#
3+
# SPDX-License-Identifier: MIT
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""Simpletest example using the Mag Tag.
2+
Use the A, B, and C buttons to change between examples."""
3+
import time
4+
import board
5+
import digitalio
6+
from adafruit_pybadger import pybadger
7+
8+
9+
def try_refresh():
10+
""" Attempt to refresh the display. Catch 'refresh too soon' error
11+
and retry after waiting 10 seconds.
12+
"""
13+
try:
14+
board.DISPLAY.refresh()
15+
except RuntimeError as too_soon_error:
16+
# catch refresh too soon
17+
print(too_soon_error)
18+
print("waiting before retry refresh()")
19+
time.sleep(10)
20+
board.DISPLAY.refresh()
21+
22+
23+
print("wait before anything")
24+
time.sleep(5)
25+
26+
btn_a = digitalio.DigitalInOut(board.BUTTON_A)
27+
btn_a.direction = digitalio.Direction.INPUT
28+
btn_a.pull = digitalio.Pull.UP
29+
30+
btn_b = digitalio.DigitalInOut(board.BUTTON_B)
31+
btn_b.direction = digitalio.Direction.INPUT
32+
btn_b.pull = digitalio.Pull.UP
33+
34+
btn_c = digitalio.DigitalInOut(board.BUTTON_C)
35+
btn_c.direction = digitalio.Direction.INPUT
36+
btn_c.pull = digitalio.Pull.UP
37+
38+
prev_a = btn_a.value
39+
prev_b = btn_b.value
40+
prev_c = btn_c.value
41+
42+
SHOWING = "badge"
43+
44+
pybadger.show_badge(
45+
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
46+
)
47+
48+
try_refresh()
49+
50+
print("after show, going to loop")
51+
52+
neopixel_pwr = digitalio.DigitalInOut(board.NEOPIXEL_POWER)
53+
neopixel_pwr.direction = digitalio.Direction.OUTPUT
54+
neopixel_pwr.value = False
55+
pybadger.pixels.fill(0x000022)
56+
57+
while True:
58+
59+
cur_a = btn_a.value
60+
cur_b = btn_b.value
61+
cur_c = btn_c.value
62+
63+
if prev_a and not cur_a:
64+
pybadger.pixels.fill(0x000000)
65+
neopixel_pwr.value = True
66+
if SHOWING != "badge":
67+
print("changing to badge")
68+
SHOWING = "badge"
69+
pybadger.show_badge(
70+
name_string="Mag Tag", hello_scale=2, my_name_is_scale=2, name_scale=3
71+
)
72+
try_refresh()
73+
74+
if prev_b and not cur_b:
75+
pybadger.pixels.fill(0x000000)
76+
neopixel_pwr.value = True
77+
if SHOWING != "qr":
78+
print("changing to qr")
79+
SHOWING = "qr"
80+
pybadger.show_qr_code(data="https://www.adafruit.com/product/4800")
81+
try_refresh()
82+
83+
if prev_c and not cur_c:
84+
pybadger.pixels.fill(0x000000)
85+
neopixel_pwr.value = True
86+
if SHOWING != "card":
87+
print("changing to card")
88+
SHOWING = "card"
89+
pybadger.show_business_card(
90+
image_name="Blinka_MagTag.bmp",
91+
name_string="Blinka",
92+
name_scale=2,
93+
email_string_one="blinka@",
94+
email_string_two="adafruit.com",
95+
)
96+
# show_business_card() calls refresh() internally
97+
98+
prev_a = cur_a
99+
prev_b = cur_b
100+
prev_c = cur_c
101+
time.sleep(1)

0 commit comments

Comments
 (0)