Skip to content

Commit 0e0ab54

Browse files
committed
headphone vs speaker usage
Short examples showing how to set volume and play WAV files for both headphone 3.5mm jack and mini speaker.
1 parent 3aebe8d commit 0e0ab54

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

examples/fruitjam_headphone.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import time
5+
import adafruit_fruitjam
6+
7+
pobj = adafruit_fruitjam.peripherals.Peripherals()
8+
dac = pobj.dac # use Fruit Jam's codec
9+
10+
# Route once for headphones
11+
dac.headphone_output = True
12+
dac.speaker_output = False
13+
14+
FILES = ["beep.wav", "dip.wav", "rise.wav"]
15+
VOLUMES_DB = [12, 6, 0, -6, -12]
16+
17+
while True:
18+
print("\n=== Headphones Test ===")
19+
for vol in VOLUMES_DB:
20+
dac.dac_volume = vol
21+
print(f"Headphones volume: {vol} dB")
22+
for f in FILES:
23+
print(f" -> {f}")
24+
pobj.play_file(f)
25+
time.sleep(0.2)
26+
time.sleep(1.0)

examples/fruitjam_speaker.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import time
5+
import adafruit_fruitjam
6+
7+
pobj = adafruit_fruitjam.peripherals.Peripherals()
8+
dac = pobj.dac # use Fruit Jam's codec
9+
10+
# Route once for speaker
11+
dac.headphone_output = False
12+
dac.speaker_output = True
13+
14+
FILES = ["beep.wav", "dip.wav", "rise.wav"]
15+
VOLUMES_DB = [12, 6, 0, -6, -12]
16+
17+
while True:
18+
print("\n=== Speaker Test ===")
19+
for vol in VOLUMES_DB:
20+
dac.dac_volume = vol
21+
print(f"Speaker volume: {vol} dB")
22+
for f in FILES:
23+
print(f" -> {f}")
24+
pobj.play_file(f)
25+
time.sleep(0.2)
26+
time.sleep(1.0)

examples/wav/beep.wav

9.14 KB
Binary file not shown.

examples/wav/dip.wav

25.9 KB
Binary file not shown.

examples/wav/rise.wav

25.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)