Merge pull request #1 from FoamyGuy/working_on_hardware
Some checks failed
Build CI / test (push) Has been cancelled
Some checks failed
Build CI / test (push) Has been cancelled
Working on hardware
This commit is contained in:
commit
df52bdf009
5 changed files with 147 additions and 1 deletions
|
|
@ -28,3 +28,30 @@ Implementation Notes
|
||||||
|
|
||||||
__version__ = "0.0.0+auto.0"
|
__version__ = "0.0.0+auto.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FruitJam.git"
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FruitJam.git"
|
||||||
|
|
||||||
|
from adafruit_fruitjam.peripherals import Peripherals
|
||||||
|
|
||||||
|
|
||||||
|
class FruitJam:
|
||||||
|
def __init__(self):
|
||||||
|
self.peripherals = Peripherals()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def neopixels(self):
|
||||||
|
return self.peripherals.neopixels
|
||||||
|
|
||||||
|
@property
|
||||||
|
def button1(self):
|
||||||
|
return self.peripherals.button1
|
||||||
|
|
||||||
|
@property
|
||||||
|
def button2(self):
|
||||||
|
return self.peripherals.button2
|
||||||
|
|
||||||
|
@property
|
||||||
|
def button3(self):
|
||||||
|
return self.peripherals.button3
|
||||||
|
|
||||||
|
@property
|
||||||
|
def audio(self):
|
||||||
|
return self.peripherals.audio
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,15 @@ Implementation Notes
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import adafruit_tlv320
|
||||||
|
import audiobusio
|
||||||
import board
|
import board
|
||||||
import displayio
|
import displayio
|
||||||
import framebufferio
|
import framebufferio
|
||||||
import picodvi
|
import picodvi
|
||||||
import supervisor
|
import supervisor
|
||||||
|
from digitalio import DigitalInOut, Direction, Pull
|
||||||
|
from neopixel import NeoPixel
|
||||||
|
|
||||||
__version__ = "0.0.0+auto.0"
|
__version__ = "0.0.0+auto.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FruitJam.git"
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FruitJam.git"
|
||||||
|
|
@ -74,3 +78,71 @@ def request_display_config(width, height):
|
||||||
color_depth=COLOR_DEPTH_LUT[width],
|
color_depth=COLOR_DEPTH_LUT[width],
|
||||||
)
|
)
|
||||||
supervisor.runtime.display = framebufferio.FramebufferDisplay(fb)
|
supervisor.runtime.display = framebufferio.FramebufferDisplay(fb)
|
||||||
|
|
||||||
|
|
||||||
|
class Peripherals:
|
||||||
|
"""Peripherals Helper Class for the FruitJam Library
|
||||||
|
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
neopixels (NeoPxiels): The NeoPixels on the Fruit Jam board.
|
||||||
|
See https://circuitpython.readthedocs.io/projects/neopixel/en/latest/api.html
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.neopixels = NeoPixel(board.NEOPIXEL, 5)
|
||||||
|
|
||||||
|
self._buttons = []
|
||||||
|
for pin in (board.BUTTON1, board.BUTTON2, board.BUTTON3):
|
||||||
|
switch = DigitalInOut(pin)
|
||||||
|
switch.direction = Direction.INPUT
|
||||||
|
switch.pull = Pull.UP
|
||||||
|
self._buttons.append(switch)
|
||||||
|
|
||||||
|
i2c = board.I2C()
|
||||||
|
self._dac = adafruit_tlv320.TLV320DAC3100(i2c)
|
||||||
|
|
||||||
|
# set sample rate & bit depth
|
||||||
|
self._dac.configure_clocks(sample_rate=11030, bit_depth=16)
|
||||||
|
|
||||||
|
# use headphones
|
||||||
|
self._dac.headphone_output = True
|
||||||
|
self._dac.headphone_volume = -15 # dB
|
||||||
|
|
||||||
|
self._audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def button1(self) -> bool:
|
||||||
|
"""
|
||||||
|
Return whether Button 1 is pressed
|
||||||
|
"""
|
||||||
|
return not self._buttons[0].value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def button2(self) -> bool:
|
||||||
|
"""
|
||||||
|
Return whether Button 2 is pressed
|
||||||
|
"""
|
||||||
|
return not self._buttons[1].value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def button3(self) -> bool:
|
||||||
|
"""
|
||||||
|
Return whether Button 3 is pressed
|
||||||
|
"""
|
||||||
|
return not self._buttons[2].value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def any_button_pressed(self) -> bool:
|
||||||
|
"""
|
||||||
|
Return whether any button is pressed
|
||||||
|
"""
|
||||||
|
return True in [button.value for (i, button) in enumerate(self._buttons)]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dac(self):
|
||||||
|
return self._dac
|
||||||
|
|
||||||
|
@property
|
||||||
|
def audio(self):
|
||||||
|
return self._audio
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ extensions = [
|
||||||
# Uncomment the below if you use native CircuitPython modules such as
|
# Uncomment the below if you use native CircuitPython modules such as
|
||||||
# digitalio, micropython and busio. List the modules you use. Without it, the
|
# digitalio, micropython and busio. List the modules you use. Without it, the
|
||||||
# autodoc module docs will fail to generate with a warning.
|
# autodoc module docs will fail to generate with a warning.
|
||||||
autodoc_mock_imports = ["displayio", "supervisor", "framebufferio", "picodvi"]
|
autodoc_mock_imports = ["displayio", "supervisor", "framebufferio", "picodvi", "audiobusio"]
|
||||||
|
|
||||||
autodoc_preserve_defaults = True
|
autodoc_preserve_defaults = True
|
||||||
|
|
||||||
|
|
|
||||||
46
examples/fruitjam_peripherals.py
Normal file
46
examples/fruitjam_peripherals.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
import time
|
||||||
|
|
||||||
|
import displayio
|
||||||
|
import supervisor
|
||||||
|
from audiocore import WaveFile
|
||||||
|
|
||||||
|
from adafruit_fruitjam import FruitJam
|
||||||
|
|
||||||
|
colors = [0xFF00FF, 0xFFFF00, 0x00FF00]
|
||||||
|
|
||||||
|
fruitjam = FruitJam()
|
||||||
|
fruitjam.neopixels.brightness = 0.1
|
||||||
|
fruitjam.neopixels.fill(0xFF00FF)
|
||||||
|
|
||||||
|
time.sleep(2)
|
||||||
|
fruitjam.neopixels.fill(0x000000)
|
||||||
|
|
||||||
|
wave_file = open("/boot_animation/ada_fruitjam_boot_jingle.wav", "rb")
|
||||||
|
wave = WaveFile(wave_file)
|
||||||
|
fruitjam.audio.play(wave)
|
||||||
|
|
||||||
|
display = supervisor.runtime.display
|
||||||
|
empty_group = displayio.Group()
|
||||||
|
display.root_group = empty_group
|
||||||
|
|
||||||
|
audio_finished = False
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if fruitjam.button1:
|
||||||
|
print("Button 1 pressed")
|
||||||
|
fruitjam.neopixels.fill(colors[0])
|
||||||
|
if fruitjam.button2:
|
||||||
|
print("Button 2 pressed")
|
||||||
|
fruitjam.neopixels.fill(colors[1])
|
||||||
|
if fruitjam.button3:
|
||||||
|
print("Button 3 pressed")
|
||||||
|
fruitjam.neopixels.fill(colors[2])
|
||||||
|
|
||||||
|
if not fruitjam.audio.playing and not audio_finished:
|
||||||
|
audio_finished = True
|
||||||
|
print("Audio playback complete")
|
||||||
|
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
@ -6,3 +6,4 @@
|
||||||
Adafruit-Blinka
|
Adafruit-Blinka
|
||||||
adafruit-circuitpython-busdevice
|
adafruit-circuitpython-busdevice
|
||||||
adafruit-circuitpython-tlv320
|
adafruit-circuitpython-tlv320
|
||||||
|
adafruit-circuitpython-neopixel
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue