Skip to content

Commit df52bdf

Browse files
authored
Merge pull request #1 from FoamyGuy/working_on_hardware
Working on hardware
2 parents 4c3a50d + e49b794 commit df52bdf

File tree

5 files changed

+147
-1
lines changed

5 files changed

+147
-1
lines changed

adafruit_fruitjam/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,30 @@
2828

2929
__version__ = "0.0.0+auto.0"
3030
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FruitJam.git"
31+
32+
from adafruit_fruitjam.peripherals import Peripherals
33+
34+
35+
class FruitJam:
36+
def __init__(self):
37+
self.peripherals = Peripherals()
38+
39+
@property
40+
def neopixels(self):
41+
return self.peripherals.neopixels
42+
43+
@property
44+
def button1(self):
45+
return self.peripherals.button1
46+
47+
@property
48+
def button2(self):
49+
return self.peripherals.button2
50+
51+
@property
52+
def button3(self):
53+
return self.peripherals.button3
54+
55+
@property
56+
def audio(self):
57+
return self.peripherals.audio

adafruit_fruitjam/peripherals.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@
2626
2727
"""
2828

29+
import adafruit_tlv320
30+
import audiobusio
2931
import board
3032
import displayio
3133
import framebufferio
3234
import picodvi
3335
import supervisor
36+
from digitalio import DigitalInOut, Direction, Pull
37+
from neopixel import NeoPixel
3438

3539
__version__ = "0.0.0+auto.0"
3640
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FruitJam.git"
@@ -74,3 +78,71 @@ def request_display_config(width, height):
7478
color_depth=COLOR_DEPTH_LUT[width],
7579
)
7680
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

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Uncomment the below if you use native CircuitPython modules such as
2525
# digitalio, micropython and busio. List the modules you use. Without it, the
2626
# autodoc module docs will fail to generate with a warning.
27-
autodoc_mock_imports = ["displayio", "supervisor", "framebufferio", "picodvi"]
27+
autodoc_mock_imports = ["displayio", "supervisor", "framebufferio", "picodvi", "audiobusio"]
2828

2929
autodoc_preserve_defaults = True
3030

examples/fruitjam_peripherals.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import time
5+
6+
import displayio
7+
import supervisor
8+
from audiocore import WaveFile
9+
10+
from adafruit_fruitjam import FruitJam
11+
12+
colors = [0xFF00FF, 0xFFFF00, 0x00FF00]
13+
14+
fruitjam = FruitJam()
15+
fruitjam.neopixels.brightness = 0.1
16+
fruitjam.neopixels.fill(0xFF00FF)
17+
18+
time.sleep(2)
19+
fruitjam.neopixels.fill(0x000000)
20+
21+
wave_file = open("/boot_animation/ada_fruitjam_boot_jingle.wav", "rb")
22+
wave = WaveFile(wave_file)
23+
fruitjam.audio.play(wave)
24+
25+
display = supervisor.runtime.display
26+
empty_group = displayio.Group()
27+
display.root_group = empty_group
28+
29+
audio_finished = False
30+
31+
while True:
32+
if fruitjam.button1:
33+
print("Button 1 pressed")
34+
fruitjam.neopixels.fill(colors[0])
35+
if fruitjam.button2:
36+
print("Button 2 pressed")
37+
fruitjam.neopixels.fill(colors[1])
38+
if fruitjam.button3:
39+
print("Button 3 pressed")
40+
fruitjam.neopixels.fill(colors[2])
41+
42+
if not fruitjam.audio.playing and not audio_finished:
43+
audio_finished = True
44+
print("Audio playback complete")
45+
46+
time.sleep(0.01)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
Adafruit-Blinka
77
adafruit-circuitpython-busdevice
88
adafruit-circuitpython-tlv320
9+
adafruit-circuitpython-neopixel

0 commit comments

Comments
 (0)