class PewPewM4(PyBadgerBase):
    """Class that represents a single Pew Pew M4."""

    _audio_out = audioio.AudioOut
    _neopixel_count = 0

    def __init__(self):
        super().__init__()

        self._buttons = GamePad(
            digitalio.DigitalInOut(board.BUTTON_O),
            digitalio.DigitalInOut(board.BUTTON_X),
            digitalio.DigitalInOut(board.BUTTON_Z),
            digitalio.DigitalInOut(board.BUTTON_RIGHT),
            digitalio.DigitalInOut(board.BUTTON_DOWN),
            digitalio.DigitalInOut(board.BUTTON_UP),
            digitalio.DigitalInOut(board.BUTTON_LEFT),
        )

    @property
    def button(self):
        """The buttons on the board.

        Example use:

        .. code-block:: python

          from adafruit_pybadger import pybadger

          while True:
              if pybadger.button.x:
                  print("Button X")
              elif pybadger.button.o:
                  print("Button O")
        """
        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,
            )
        ])

    @property
    def _unsupported(self):
        """This feature is not supported on PewPew M4."""
        raise NotImplementedError(
            "This feature is not supported on PewPew M4.")

    # 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.
    light = _unsupported
    acceleration = _unsupported
    pixels = _unsupported
Esempio n. 2
0
class CPB_Gizmo(PyBadgerBase):
    """Class that represents a single Circuit Playground Bluefruit with TFT Gizmo."""

    display = None
    _audio_out = audiopwmio.PWMAudioOut
    _neopixel_count = 10

    def __init__(self):
        super().__init__()

        _i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
        _int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
        self.accelerometer = adafruit_lis3dh.LIS3DH_I2C(_i2c,
                                                        address=0x19,
                                                        int1=_int1)
        self.accelerometer.range = adafruit_lis3dh.RANGE_8_G

        self.display = tft_gizmo.TFT_Gizmo()
        self._display_brightness = 1.0

        # NeoPixels
        self._neopixels = neopixel.NeoPixel(board.NEOPIXEL,
                                            self._neopixel_count,
                                            brightness=1,
                                            pixel_order=neopixel.GRB)
        _a_btn = digitalio.DigitalInOut(board.BUTTON_A)
        _a_btn.switch_to_input(pull=digitalio.Pull.DOWN)
        _b_btn = digitalio.DigitalInOut(board.BUTTON_B)
        _b_btn.switch_to_input(pull=digitalio.Pull.DOWN)
        self._buttons = GamePad(_a_btn, _b_btn)
        self._light_sensor = analogio.AnalogIn(board.LIGHT)

    @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 CPB Gizmo."""
        raise NotImplementedError(
            "This feature is not supported on CPB Gizmo.")
Esempio n. 3
0
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)

        # NeoPixels
        self._neopixels = neopixel.NeoPixel(board.NEOPIXEL,
                                            self._neopixel_count,
                                            brightness=1,
                                            pixel_order=neopixel.GRB)

        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