Skip to content

Commit 2589e54

Browse files
committed
adding support for Pew Pew M4. refactor neopixels into the board specific modules.
1 parent caaedca commit 2589e54

File tree

8 files changed

+82
-21
lines changed

8 files changed

+82
-21
lines changed

adafruit_pybadger/clue.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import audiopwmio
4949
from gamepad import GamePad
5050
import adafruit_lsm6ds
51+
import neopixel
5152
from adafruit_pybadger.pybadger_base import PyBadgerBase
5253

5354
__version__ = "0.0.0-auto.0"
@@ -70,6 +71,11 @@ def __init__(self):
7071
if i2c is not None:
7172
self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c)
7273

74+
# NeoPixels
75+
self._neopixels = neopixel.NeoPixel(
76+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
77+
)
78+
7379
self._buttons = GamePad(
7480
digitalio.DigitalInOut(board.BUTTON_A),
7581
digitalio.DigitalInOut(board.BUTTON_B),

adafruit_pybadger/pewpewm4.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@
4747
import digitalio
4848
import audioio
4949
from gamepad import GamePad
50-
import adafruit_lsm6ds
5150
from adafruit_pybadger.pybadger_base import PyBadgerBase
5251

5352
__version__ = "0.0.0-auto.0"
5453
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
5554

56-
Buttons = namedtuple("Buttons", "b a start right down up left")
55+
Buttons = namedtuple("Buttons", ("o", "x", "z", "right", "down", "up", "left"))
5756

5857

5958
class PewPewM4(PyBadgerBase):
@@ -65,10 +64,14 @@ class PewPewM4(PyBadgerBase):
6564
def __init__(self):
6665
super().__init__()
6766

68-
6967
self._buttons = GamePad(
70-
digitalio.DigitalInOut(board.BUTTON_A),
71-
digitalio.DigitalInOut(board.BUTTON_B),
68+
digitalio.DigitalInOut(board.BUTTON_O),
69+
digitalio.DigitalInOut(board.BUTTON_X),
70+
digitalio.DigitalInOut(board.BUTTON_Z),
71+
digitalio.DigitalInOut(board.BUTTON_RIGHT),
72+
digitalio.DigitalInOut(board.BUTTON_DOWN),
73+
digitalio.DigitalInOut(board.BUTTON_UP),
74+
digitalio.DigitalInOut(board.BUTTON_LEFT),
7275
)
7376

7477
@property
@@ -82,27 +85,39 @@ def button(self):
8285
from adafruit_pybadger import pybadger
8386
8487
while True:
85-
if pybadger.button.a:
86-
print("Button A")
87-
elif pybadger.button.b:
88-
print("Button B")
88+
if pybadger.button.x:
89+
print("Button X")
90+
elif pybadger.button.o:
91+
print("Button O")
8992
"""
9093
button_values = self._buttons.get_pressed()
9194
return Buttons(
92-
button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A
95+
*[
96+
button_values & button
97+
for button in (
98+
PyBadgerBase.BUTTON_B,
99+
PyBadgerBase.BUTTON_A,
100+
PyBadgerBase.BUTTON_START,
101+
PyBadgerBase.BUTTON_SELECT,
102+
PyBadgerBase.BUTTON_RIGHT,
103+
PyBadgerBase.BUTTON_DOWN,
104+
PyBadgerBase.BUTTON_UP,
105+
)
106+
]
93107
)
94108

95109
@property
96110
def _unsupported(self):
97-
"""This feature is not supported on CLUE."""
98-
raise NotImplementedError("This feature is not supported on CLUE.")
111+
"""This feature is not supported on PewPew M4."""
112+
raise NotImplementedError("This feature is not supported on PewPew M4.")
99113

100114
# The following is a list of the features available in other PyBadger modules but
101115
# not available for CLUE. If called while using a CLUE, they will result in the
102116
# NotImplementedError raised in the property above.
103117
light = _unsupported
118+
acceleration = _unsupported
119+
pixels = _unsupported
104120

105121

106-
107-
clue = Clue() # pylint: disable=invalid-name
122+
pewpewm4 = PewPewM4() # pylint: disable=invalid-name
108123
"""Object that is automatically created on import."""

adafruit_pybadger/pybadge.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import audioio
5555
from gamepadshift import GamePadShift
5656
import adafruit_lis3dh
57+
import neopixel
5758
from adafruit_pybadger.pybadger_base import PyBadgerBase
5859

5960
__version__ = "0.0.0-auto.0"
@@ -88,6 +89,11 @@ def __init__(self):
8889
except ValueError:
8990
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
9091

92+
# NeoPixels
93+
self._neopixels = neopixel.NeoPixel(
94+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
95+
)
96+
9197
self._buttons = GamePadShift(
9298
digitalio.DigitalInOut(board.BUTTON_CLOCK),
9399
digitalio.DigitalInOut(board.BUTTON_OUT),

adafruit_pybadger/pybadger_base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
except ImportError:
5757
import audioio as audiocore
5858
import displayio
59-
import neopixel
6059
from adafruit_display_shapes.rect import Rect
6160
from adafruit_display_text import label
6261
from adafruit_bitmap_font import bitmap_font
@@ -136,11 +135,6 @@ def __init__(self):
136135
self.display = board.DISPLAY
137136
self._display_brightness = 1.0
138137

139-
# NeoPixels
140-
self._neopixels = neopixel.NeoPixel(
141-
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
142-
)
143-
144138
# Auto dim display based on movement
145139
self._last_accelerometer = None
146140
self._start_time = time.monotonic()

adafruit_pybadger/pygamer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import analogio
4848
import digitalio
4949
import audioio
50+
import neopixel
5051
from gamepadshift import GamePadShift
5152
import adafruit_lis3dh
5253
from adafruit_pybadger.pybadger_base import PyBadgerBase
@@ -76,6 +77,11 @@ def __init__(self):
7677
except ValueError:
7778
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
7879

80+
# NeoPixels
81+
self._neopixels = neopixel.NeoPixel(
82+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
83+
)
84+
7985
self._buttons = GamePadShift(
8086
digitalio.DigitalInOut(board.BUTTON_CLOCK),
8187
digitalio.DigitalInOut(board.BUTTON_OUT),

adafruit_pybadger/pyportal.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
https://github.com/adafruit/circuitpython/releases
4242
4343
"""
44-
44+
import board
4545
import audioio
46+
import neopixel
4647
from adafruit_pybadger.pybadger_base import PyBadgerBase
4748

4849
__version__ = "0.0.0-auto.0"
@@ -55,6 +56,14 @@ class PyPortal(PyBadgerBase):
5556
_audio_out = audioio.AudioOut
5657
_neopixel_count = 1
5758

59+
def __init__(self):
60+
super().__init__()
61+
62+
# NeoPixels
63+
self._neopixels = neopixel.NeoPixel(
64+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
65+
)
66+
5867
@property
5968
def _unsupported(self):
6069
"""This feature is not supported on PyPortal."""

examples/Blinka_PewPewM4.bmp

11.1 KB
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Simpletest example using the Pew Pew M4.
2+
Use the O, X, and Z buttons to change between examples."""
3+
from adafruit_pybadger import pybadger
4+
5+
pybadger.show_badge(
6+
name_string="Blinka", hello_scale=3, my_name_is_scale=3, name_scale=4
7+
)
8+
9+
while True:
10+
if pybadger.button.o:
11+
pybadger.show_business_card(
12+
image_name="Blinka_PewPewM4.bmp",
13+
name_string="Blinka",
14+
name_scale=4,
15+
email_string_one="blinka@",
16+
email_string_two="adafruit.com",
17+
email_scale_one=2,
18+
email_scale_two=2,
19+
)
20+
elif pybadger.button.x:
21+
pybadger.show_qr_code(data="https://circuitpython.org")
22+
elif pybadger.button.z:
23+
pybadger.show_badge(
24+
name_string="Blinka", hello_scale=3, my_name_is_scale=3, name_scale=4
25+
)

0 commit comments

Comments
 (0)