|
26 | 26 |
|
27 | 27 | """ |
28 | 28 |
|
| 29 | +import adafruit_tlv320 |
| 30 | +import audiobusio |
29 | 31 | import board |
30 | 32 | import displayio |
31 | 33 | import framebufferio |
32 | 34 | import picodvi |
33 | 35 | import supervisor |
| 36 | +from digitalio import DigitalInOut, Direction, Pull |
| 37 | +from neopixel import NeoPixel |
34 | 38 |
|
35 | 39 | __version__ = "0.0.0+auto.0" |
36 | 40 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FruitJam.git" |
@@ -74,3 +78,71 @@ def request_display_config(width, height): |
74 | 78 | color_depth=COLOR_DEPTH_LUT[width], |
75 | 79 | ) |
76 | 80 | supervisor.runtime.display = framebufferio.FramebufferDisplay(fb) |
| 81 | + |
| 82 | + |
| 83 | +class Peripherals: |
| 84 | + """Peripherals Helper Class for the FruitJam Library |
| 85 | +
|
| 86 | +
|
| 87 | + Attributes: |
| 88 | + neopixels (NeoPxiels): The NeoPixels on the Fruit Jam board. |
| 89 | + See https://circuitpython.readthedocs.io/projects/neopixel/en/latest/api.html |
| 90 | + """ |
| 91 | + |
| 92 | + def __init__(self): |
| 93 | + self.neopixels = NeoPixel(board.NEOPIXEL, 5) |
| 94 | + |
| 95 | + self._buttons = [] |
| 96 | + for pin in (board.BUTTON1, board.BUTTON2, board.BUTTON3): |
| 97 | + switch = DigitalInOut(pin) |
| 98 | + switch.direction = Direction.INPUT |
| 99 | + switch.pull = Pull.UP |
| 100 | + self._buttons.append(switch) |
| 101 | + |
| 102 | + i2c = board.I2C() |
| 103 | + self._dac = adafruit_tlv320.TLV320DAC3100(i2c) |
| 104 | + |
| 105 | + # set sample rate & bit depth |
| 106 | + self._dac.configure_clocks(sample_rate=11030, bit_depth=16) |
| 107 | + |
| 108 | + # use headphones |
| 109 | + self._dac.headphone_output = True |
| 110 | + self._dac.headphone_volume = -15 # dB |
| 111 | + |
| 112 | + self._audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN) |
| 113 | + |
| 114 | + @property |
| 115 | + def button1(self) -> bool: |
| 116 | + """ |
| 117 | + Return whether Button 1 is pressed |
| 118 | + """ |
| 119 | + return not self._buttons[0].value |
| 120 | + |
| 121 | + @property |
| 122 | + def button2(self) -> bool: |
| 123 | + """ |
| 124 | + Return whether Button 2 is pressed |
| 125 | + """ |
| 126 | + return not self._buttons[1].value |
| 127 | + |
| 128 | + @property |
| 129 | + def button3(self) -> bool: |
| 130 | + """ |
| 131 | + Return whether Button 3 is pressed |
| 132 | + """ |
| 133 | + return not self._buttons[2].value |
| 134 | + |
| 135 | + @property |
| 136 | + def any_button_pressed(self) -> bool: |
| 137 | + """ |
| 138 | + Return whether any button is pressed |
| 139 | + """ |
| 140 | + return True in [button.value for (i, button) in enumerate(self._buttons)] |
| 141 | + |
| 142 | + @property |
| 143 | + def dac(self): |
| 144 | + return self._dac |
| 145 | + |
| 146 | + @property |
| 147 | + def audio(self): |
| 148 | + return self._audio |
0 commit comments