diff --git a/README.rst b/README.rst
index a5eec5a..4082d3d 100644
--- a/README.rst
+++ b/README.rst
@@ -13,7 +13,7 @@ Introduction
:target: https://github.com/adafruit/Adafruit_CircuitPython_PyBadger/actions/
:alt: Build Status
-Badge-focused CircuitPython helper library for PyBadge and PyGamer.
+Badge-focused CircuitPython helper library for PyBadge, PyBadge LC, PyGamer and CLUE.
Dependencies
@@ -28,9 +28,6 @@ This is easily achieved by downloading
Installing from PyPI
=====================
-.. note:: This library is not available on PyPI yet. Install documentation is included
- as a standard element. Stay tuned for PyPI availability!
-
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
PyPI `_. To install for current user:
@@ -58,9 +55,7 @@ Usage Example
.. code-block:: python
- from adafruit_pybadger import PyBadger
-
- pybadger = PyBadger()
+ from adafruit_pybadger import pybadger
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
diff --git a/adafruit_pybadger/__init__.py b/adafruit_pybadger/__init__.py
new file mode 100755
index 0000000..f4a5228
--- /dev/null
+++ b/adafruit_pybadger/__init__.py
@@ -0,0 +1,33 @@
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+"""
+Verifies which board is being used and imports the appropriate module.
+"""
+
+import os
+
+if "CLUE" in os.uname().machine:
+ from .clue import clue as pybadger
+elif "Pybadge" in os.uname().machine:
+ from .pybadge import pybadge as pybadger
+elif "PyGamer" in os.uname().machine:
+ from .pygamer import pygamer as pybadger
diff --git a/adafruit_pybadger/clue.py b/adafruit_pybadger/clue.py
new file mode 100755
index 0000000..ba6aeab
--- /dev/null
+++ b/adafruit_pybadger/clue.py
@@ -0,0 +1,107 @@
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+"""
+`adafruit_pybadger.clue`
+================================================================================
+
+Badge-focused CircuitPython helper library for CLUE.
+
+
+* Author(s): Kattni Rembor
+
+Implementation Notes
+--------------------
+
+**Hardware:**
+
+* `Adafruit CLUE `_
+
+**Software and Dependencies:**
+
+* Adafruit CircuitPython firmware for the supported boards:
+ https://github.com/adafruit/circuitpython/releases
+
+"""
+
+from collections import namedtuple
+import board
+import digitalio
+import audiopwmio
+from gamepad import GamePad
+import adafruit_lsm6ds
+from adafruit_pybadger.pybadger_base import PyBadgerBase
+
+__version__ = "0.0.0-auto.0"
+__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
+
+Buttons = namedtuple("Buttons", "a b")
+
+class Clue(PyBadgerBase):
+ """Class that represents a single CLUE."""
+ _audio_out = audiopwmio.PWMAudioOut
+ _neopixel_count = 1
+
+ def __init__(self):
+ super().__init__()
+
+ i2c = board.I2C()
+
+ if i2c is not None:
+ self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c)
+
+ self._buttons = GamePad(digitalio.DigitalInOut(board.BUTTON_A),
+ digitalio.DigitalInOut(board.BUTTON_B))
+
+ @property
+ def button(self):
+ """The buttons on the board.
+
+ Example use:
+
+ .. code-block:: python
+
+ from adafruit_pybadger import pybadger
+
+ while True:
+ if pybadger.button.a:
+ print("Button A")
+ elif pybadger.button.b:
+ print("Button B")
+ """
+ button_values = self._buttons.get_pressed()
+ return Buttons(button_values & PyBadgerBase.BUTTON_B,
+ button_values & PyBadgerBase.BUTTON_A)
+
+
+ @property
+ def _unsupported(self):
+ """This feature is not supported on CLUE."""
+ raise NotImplementedError("This feature is not supported on CLUE.")
+
+ # The following is a list of the features available in other PyBadger modules but
+ # not available for CLUE. If called while using a CLUE, they will result in the
+ # NotImplementedError raised in the property above.
+ play_file = _unsupported
+ light = _unsupported
+
+clue = Clue() # pylint: disable=invalid-name
+"""Object that is automatically created on import."""
diff --git a/adafruit_pybadger/pybadge.py b/adafruit_pybadger/pybadge.py
new file mode 100755
index 0000000..deb75ba
--- /dev/null
+++ b/adafruit_pybadger/pybadge.py
@@ -0,0 +1,123 @@
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+"""
+`adafruit_pybadger.pybadge`
+================================================================================
+
+Badge-focused CircuitPython helper library for PyBadge, PyBadge LC and EdgeBadge.
+All three boards are included in this module as there is no difference in the
+CircuitPython builds at this time, and therefore no way to differentiate
+the boards from within CircuitPython.
+
+
+* Author(s): Kattni Rembor
+
+Implementation Notes
+--------------------
+
+**Hardware:**
+
+* `Adafruit PyBadge `_
+* `Adafruit PyBadge LC `_
+* `Adafruit EdgeBadge `_
+
+**Software and Dependencies:**
+
+* Adafruit CircuitPython firmware for the supported boards:
+ https://github.com/adafruit/circuitpython/releases
+
+"""
+
+from collections import namedtuple
+import board
+import digitalio
+import analogio
+import audioio
+from gamepadshift import GamePadShift
+import adafruit_lis3dh
+from adafruit_pybadger.pybadger_base import PyBadgerBase
+
+__version__ = "0.0.0-auto.0"
+__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
+
+Buttons = namedtuple("Buttons", "b a start select right down up left")
+
+class PyBadge(PyBadgerBase):
+ """Class that represents a single PyBadge, PyBadge LC, or EdgeBadge."""
+
+ _audio_out = audioio.AudioOut
+ _neopixel_count = 5
+
+ def __init__(self):
+ super().__init__()
+
+ i2c = None
+
+ if i2c is None:
+ try:
+ i2c = board.I2C()
+ except RuntimeError:
+ self._accelerometer = None
+
+ if i2c is not None:
+ int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
+ try:
+ self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
+ except ValueError:
+ self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
+
+ self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
+ digitalio.DigitalInOut(board.BUTTON_OUT),
+ digitalio.DigitalInOut(board.BUTTON_LATCH))
+
+ self._light_sensor = analogio.AnalogIn(board.A7)
+
+ @property
+ def button(self):
+ """The buttons on the board.
+
+ Example use:
+
+ .. code-block:: python
+
+ from adafruit_pybadger import 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")
+
+ """
+ button_values = self._buttons.get_pressed()
+ return Buttons(*[button_values & button for button in
+ (PyBadgerBase.BUTTON_B, PyBadgerBase.BUTTON_A,
+ PyBadgerBase.BUTTON_START, PyBadgerBase.BUTTON_SELECT,
+ PyBadgerBase.BUTTON_RIGHT, PyBadgerBase.BUTTON_DOWN,
+ PyBadgerBase.BUTTON_UP, PyBadgerBase.BUTTON_LEFT)])
+
+pybadge = PyBadge() # pylint: disable=invalid-name
+"""Object that is automatically created on import."""
diff --git a/adafruit_pybadger.py b/adafruit_pybadger/pybadger_base.py
similarity index 80%
rename from adafruit_pybadger.py
rename to adafruit_pybadger/pybadger_base.py
index 41bad8a..98c2517 100755
--- a/adafruit_pybadger.py
+++ b/adafruit_pybadger/pybadger_base.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
#
-# Copyright (c) 2019 Kattni Rembor for Adafruit Industries
+# Copyright (c) 2019-2020 Kattni Rembor for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -20,10 +20,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
-`adafruit_pybadger`
+`adafruit_pybadger.pybadger_base`
================================================================================
-Badge-focused CircuitPython helper library for PyBadge and PyGamer.
+Base class for badge-focused CircuitPython helper library.
* Author(s): Kattni Rembor
@@ -33,6 +33,7 @@
**Hardware:**
+* `Adafruit CLUE `_
* `Adafruit PyBadge `_
* `Adafruit PyBadge LC `_
* `Adafruit PyGamer `_
@@ -47,27 +48,24 @@
import time
import array
import math
-from collections import namedtuple
import board
from micropython import const
import digitalio
-import analogio
-import audioio
+try:
+ import audiocore
+except ImportError:
+ import audioio as audiocore
import displayio
-from gamepadshift import GamePadShift
import neopixel
from adafruit_display_shapes.rect import Rect
from adafruit_display_text.label import Label
from adafruit_bitmap_font import bitmap_font
import terminalio
import adafruit_miniqr
-import adafruit_lis3dh
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
-Buttons = namedtuple("Buttons", "b a start select right down up left")
-
def load_font(fontname, text):
"""Load a font and glyphs in the text string
@@ -80,8 +78,12 @@ def load_font(fontname, text):
return font
# pylint: disable=too-many-instance-attributes
-class PyBadger:
- """PyBadger class."""
+class PyBadgerBase:
+ """PyBadger base class."""
+
+ _audio_out = None
+ _neopixel_count = None
+
# Button Constants
BUTTON_LEFT = const(128)
BUTTON_UP = const(64)
@@ -92,42 +94,16 @@ class PyBadger:
BUTTON_A = const(2)
BUTTON_B = const(1)
- def __init__(self, i2c=None, *, pixels_brightness=1.0):
- # Accelerometer
- if i2c is None:
- try:
- i2c = board.I2C()
- except RuntimeError:
- self._accelerometer = None
-
- if i2c is not None:
- int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
- try:
- self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
- except ValueError:
- self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
-
- # Buttons
- self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
- digitalio.DigitalInOut(board.BUTTON_OUT),
- digitalio.DigitalInOut(board.BUTTON_LATCH))
+ def __init__(self, *, pixels_brightness=1.0):
+ self._light_sensor = None
+ self._accelerometer = None
# Display
self.display = board.DISPLAY
self._display_brightness = 1.0
- # Light sensor
- self._light_sensor = analogio.AnalogIn(board.A7)
-
- # PyGamer joystick
- if hasattr(board, "JOYSTICK_X"):
- self._pygamer_joystick_x = analogio.AnalogIn(board.JOYSTICK_X)
- self._pygamer_joystick_y = analogio.AnalogIn(board.JOYSTICK_Y)
-
# NeoPixels
- # Count is hardcoded - should be based on board ID, currently no board info for PyBadge LC
- neopixel_count = 5
- self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, neopixel_count,
+ self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, self._neopixel_count,
brightness=pixels_brightness, pixel_order=neopixel.GRB)
# Auto dim display based on movement
@@ -135,8 +111,9 @@ def __init__(self, i2c=None, *, pixels_brightness=1.0):
self._start_time = time.monotonic()
# Define audio:
- self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
- self._speaker_enable.switch_to_output(value=False)
+ if hasattr(board, "SPEAKER_ENABLE"):
+ self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
+ self._speaker_enable.switch_to_output(value=False)
self._sample = None
self._sine_wave = None
self._sine_wave_sample = None
@@ -191,57 +168,6 @@ def pixels(self):
"""Sequence like object representing the NeoPixels on the board."""
return self._neopixels
- @property
- def joystick(self):
- """The joystick on the PyGamer."""
- if hasattr(board, "JOYSTICK_X"):
- x = self._pygamer_joystick_x.value
- y = self._pygamer_joystick_y.value
- return x, y
- raise RuntimeError("This board does not have a built in joystick.")
-
- @property
- def button(self):
- """The buttons on the board.
-
- Example use:
-
- .. code-block:: python
-
- 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")
-
- """
- #pylint: disable=no-else-return
- button_values = self._buttons.get_pressed()
- if hasattr(board, "JOYSTICK_X"):
- x, y = self.joystick
- return Buttons(button_values & PyBadger.BUTTON_B,
- button_values & PyBadger.BUTTON_A,
- button_values & PyBadger.BUTTON_START,
- button_values & PyBadger.BUTTON_SELECT,
- x > 50000, # RIGHT
- y > 50000, # DOWN
- y < 15000, # UP
- x < 15000 # LEFT
- )
- else:
- return Buttons(*[button_values & button for button in
- (PyBadger.BUTTON_B, PyBadger.BUTTON_A, PyBadger.BUTTON_START,
- PyBadger.BUTTON_SELECT, PyBadger.BUTTON_RIGHT,
- PyBadger.BUTTON_DOWN, PyBadger.BUTTON_UP, PyBadger.BUTTON_LEFT)])
-
@property
def light(self):
"""Light sensor data."""
@@ -415,7 +341,6 @@ def show_qr_code(self, *, data="https://circuitpython.org"):
"""Generate a QR code and display it for ``dwell`` seconds.
:param string data: A string of data for the QR code
- :param int dwell: The amount of time in seconds to display the QR code
"""
qr_code = adafruit_miniqr.QRCode(qr_type=3, error_correct=adafruit_miniqr.L)
@@ -445,9 +370,14 @@ def _sine_sample(length):
def _generate_sample(self, length=100):
if self._sample is not None:
return
- self._sine_wave = array.array("H", PyBadger._sine_sample(length))
- self._sample = audioio.AudioOut(board.SPEAKER)
- self._sine_wave_sample = audioio.RawSample(self._sine_wave)
+ self._sine_wave = array.array("H", PyBadgerBase._sine_sample(length))
+ self._sample = self._audio_out(board.SPEAKER) # pylint: disable=not-callable
+ self._sine_wave_sample = audiocore.RawSample(self._sine_wave)
+
+ def _enable_speaker(self, enable):
+ if not hasattr(board, "SPEAKER_ENABLE"):
+ return
+ self._speaker_enable.value = enable
def play_tone(self, frequency, duration):
""" Produce a tone using the speaker. Try changing frequency to change
@@ -469,7 +399,7 @@ def start_tone(self, frequency):
:param int frequency: The frequency of the tone in Hz
"""
- self._speaker_enable.value = True
+ self._enable_speaker(enable=True)
length = 100
if length * frequency > 350000:
length = 350000 // frequency
@@ -481,14 +411,13 @@ def start_tone(self, frequency):
def stop_tone(self):
""" Use with start_tone to stop the tone produced.
-
"""
# Stop playing any tones.
if self._sample is not None and self._sample.playing:
self._sample.stop()
self._sample.deinit()
self._sample = None
- self._speaker_enable.value = False
+ self._enable_speaker(enable=False)
def play_file(self, file_name):
""" Play a .wav file using the onboard speaker.
@@ -498,10 +427,10 @@ def play_file(self, file_name):
"""
# Play a specified file.
self.stop_tone()
- self._speaker_enable.value = True
- with audioio.AudioOut(board.SPEAKER) as audio:
- wavefile = audioio.WaveFile(open(file_name, "rb"))
+ self._enable_speaker(enable=True)
+ with self._audio_out(board.SPEAKER) as audio: # pylint: disable=not-callable
+ wavefile = audiocore.WaveFile(open(file_name, "rb"))
audio.play(wavefile)
while audio.playing:
pass
- self._speaker_enable.value = False
+ self._enable_speaker(enable=True)
diff --git a/adafruit_pybadger/pygamer.py b/adafruit_pybadger/pygamer.py
new file mode 100755
index 0000000..94fffba
--- /dev/null
+++ b/adafruit_pybadger/pygamer.py
@@ -0,0 +1,126 @@
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+"""
+`adafruit_pybadger.pygamer`
+================================================================================
+
+Badge-focused CircuitPython helper library for PyGamer.
+
+
+* Author(s): Kattni Rembor
+
+Implementation Notes
+--------------------
+
+**Hardware:**
+
+* `Adafruit PyGamer `_
+
+**Software and Dependencies:**
+
+* Adafruit CircuitPython firmware for the supported boards:
+ https://github.com/adafruit/circuitpython/releases
+
+"""
+
+from collections import namedtuple
+import board
+import analogio
+import digitalio
+import audioio
+from gamepadshift import GamePadShift
+import adafruit_lis3dh
+from adafruit_pybadger.pybadger_base import PyBadgerBase
+
+__version__ = "0.0.0-auto.0"
+__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
+
+Buttons = namedtuple("Buttons", "b a start select right down up left")
+
+class PyGamer(PyBadgerBase):
+ """Class that represents a single PyGamer."""
+
+ _audio_out = audioio.AudioOut
+ _neopixel_count = 5
+
+ def __init__(self):
+ super().__init__()
+
+ i2c = board.I2C()
+
+ int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
+ try:
+ self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
+ except ValueError:
+ self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
+
+ self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
+ digitalio.DigitalInOut(board.BUTTON_OUT),
+ digitalio.DigitalInOut(board.BUTTON_LATCH))
+
+ self._pygamer_joystick_x = analogio.AnalogIn(board.JOYSTICK_X)
+ self._pygamer_joystick_y = analogio.AnalogIn(board.JOYSTICK_Y)
+
+ self._light_sensor = analogio.AnalogIn(board.A7)
+
+ @property
+ def button(self):
+ """The buttons on the board.
+
+ Example use:
+
+ .. code-block:: python
+
+ from adafruit_pybadger import 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")
+
+ """
+ button_values = self._buttons.get_pressed()
+ x, y = self.joystick
+ return Buttons(button_values & PyBadgerBase.BUTTON_B,
+ button_values & PyBadgerBase.BUTTON_A,
+ button_values & PyBadgerBase.BUTTON_START,
+ button_values & PyBadgerBase.BUTTON_SELECT,
+ x > 50000, # RIGHT
+ y > 50000, # DOWN
+ y < 15000, # UP
+ x < 15000 # LEFT
+ )
+
+ @property
+ def joystick(self):
+ """The joystick on the PyGamer."""
+ x = self._pygamer_joystick_x.value
+ y = self._pygamer_joystick_y.value
+ return x, y
+
+pygamer = PyGamer() # pylint: disable=invalid-name
+"""Object that is automatically created on import."""
diff --git a/docs/api.rst b/docs/api.rst
index fc22c47..c264f39 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -4,5 +4,14 @@
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
.. use this format as the module name: "adafruit_foo.foo"
-.. automodule:: adafruit_pybadger
+.. automodule:: adafruit_pybadger.pybadger_base
+ :members:
+
+.. automodule:: adafruit_pybadger.clue
+ :members:
+
+.. automodule:: adafruit_pybadger.pybadge
+ :members:
+
+.. automodule:: adafruit_pybadger.pygamer
:members:
diff --git a/docs/conf.py b/docs/conf.py
index 18cabce..a1bcd90 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -22,8 +22,9 @@
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["audioio", "displayio", "gamepadshift", "neopixel", "analogio",
"adafruit_display_shapes", "adafruit_display_text", "terminalio",
- "adafruit_miniqr", "adafruit_lis3dh", "adafruit_miniqr",
- "adafruit_bitmap_font"]
+ "adafruit_miniqr", "adafruit_lis3dh", "adafruit_bitmap_font",
+ "adafruit_lsm6ds", "gamepad", "audiocore", "audiopwmio", "micropython",
+ "terminalio", "digitalio", "board"]
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
diff --git a/examples/pybadger_simpletest.py b/examples/pybadger_simpletest.py
index 836fd13..6dba7f8 100644
--- a/examples/pybadger_simpletest.py
+++ b/examples/pybadger_simpletest.py
@@ -1,6 +1,4 @@
-from adafruit_pybadger import PyBadger
-
-pybadger = PyBadger()
+from adafruit_pybadger import pybadger
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
diff --git a/setup.py b/setup.py
index 5b7dd13..6ef62d0 100644
--- a/setup.py
+++ b/setup.py
@@ -59,5 +59,5 @@
# simple. Or you can use find_packages().
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
# CHANGE `py_modules=['...']` TO `packages=['...']`
- py_modules=['adafruit_pybadger'],
+ packages=['adafruit_pybadger'],
)