/ adafruit_pybadger / clue.py
clue.py
1 # The MIT License (MIT) 2 # 3 # Copyright (c) 2020 Kattni Rembor for Adafruit Industries 4 # 5 # Permission is hereby granted, free of charge, to any person obtaining a copy 6 # of this software and associated documentation files (the "Software"), to deal 7 # in the Software without restriction, including without limitation the rights 8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 # copies of the Software, and to permit persons to whom the Software is 10 # furnished to do so, subject to the following conditions: 11 # 12 # The above copyright notice and this permission notice shall be included in 13 # all copies or substantial portions of the Software. 14 # 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 # THE SOFTWARE. 22 """ 23 `adafruit_pybadger.clue` 24 ================================================================================ 25 26 Badge-focused CircuitPython helper library for CLUE. 27 28 29 * Author(s): Kattni Rembor 30 31 Implementation Notes 32 -------------------- 33 34 **Hardware:** 35 36 * `Adafruit CLUE <https://www.adafruit.com/product/4500>`_ 37 38 **Software and Dependencies:** 39 40 * Adafruit CircuitPython firmware for the supported boards: 41 https://github.com/adafruit/circuitpython/releases 42 43 """ 44 45 from collections import namedtuple 46 import board 47 import digitalio 48 import audiopwmio 49 from gamepad import GamePad 50 import adafruit_lsm6ds 51 import neopixel 52 from adafruit_pybadger.pybadger_base import PyBadgerBase 53 54 __version__ = "0.0.0-auto.0" 55 __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git" 56 57 Buttons = namedtuple("Buttons", "a b") 58 59 60 class Clue(PyBadgerBase): 61 """Class that represents a single CLUE.""" 62 63 _audio_out = audiopwmio.PWMAudioOut 64 _neopixel_count = 1 65 66 def __init__(self): 67 super().__init__() 68 69 i2c = board.I2C() 70 71 if i2c is not None: 72 self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c) 73 74 # NeoPixels 75 self._neopixels = neopixel.NeoPixel( 76 board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB 77 ) 78 79 self._buttons = GamePad( 80 digitalio.DigitalInOut(board.BUTTON_A), 81 digitalio.DigitalInOut(board.BUTTON_B), 82 ) 83 84 @property 85 def button(self): 86 """The buttons on the board. 87 88 Example use: 89 90 .. code-block:: python 91 92 from adafruit_pybadger import pybadger 93 94 while True: 95 if pybadger.button.a: 96 print("Button A") 97 elif pybadger.button.b: 98 print("Button B") 99 """ 100 button_values = self._buttons.get_pressed() 101 return Buttons( 102 button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A 103 ) 104 105 @property 106 def _unsupported(self): 107 """This feature is not supported on CLUE.""" 108 raise NotImplementedError("This feature is not supported on CLUE.") 109 110 # The following is a list of the features available in other PyBadger modules but 111 # not available for CLUE. If called while using a CLUE, they will result in the 112 # NotImplementedError raised in the property above. 113 play_file = _unsupported 114 light = _unsupported 115 116 117 clue = Clue() # pylint: disable=invalid-name 118 """Object that is automatically created on import."""