Skip to content

Commit 6252a41

Browse files
authored
Merge pull request #2827 from adafruit/dune_thumper
Code for the Dune Thumper project
2 parents fcf40b5 + 71946c4 commit 6252a41

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Dune_Thumper/code.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
import audiocore
8+
import audiobusio
9+
import audiomixer
10+
import pwmio
11+
from digitalio import DigitalInOut, Direction
12+
from adafruit_ticks import ticks_ms, ticks_add, ticks_diff
13+
from adafruit_motor import servo
14+
import adafruit_lis3dh
15+
16+
time.sleep(2)
17+
18+
# enable external power pin
19+
# provides power to the external components
20+
external_power = DigitalInOut(board.EXTERNAL_POWER)
21+
external_power.direction = Direction.OUTPUT
22+
external_power.value = True
23+
24+
# i2s playback
25+
wave_file = open("dune_thumper_sfx.wav", "rb")
26+
wave = audiocore.WaveFile(wave_file)
27+
audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
28+
mixer = audiomixer.Mixer(voice_count=1, sample_rate=22050, channel_count=1,
29+
bits_per_sample=16, samples_signed=True)
30+
audio.play(mixer)
31+
mixer.voice[0].play(wave, loop=True)
32+
mixer.voice[0].level = 0
33+
34+
# servo control
35+
pwm = pwmio.PWMOut(board.EXTERNAL_SERVO, frequency=10)
36+
prop_servo = servo.ContinuousServo(pwm)
37+
servo_move = False
38+
39+
i2c = board.I2C()
40+
int1 = DigitalInOut(board.ACCELEROMETER_INTERRUPT)
41+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
42+
lis3dh.range = adafruit_lis3dh.RANGE_2_G
43+
44+
clock = ticks_ms()
45+
prop_time = 4000
46+
47+
while True:
48+
if not servo_move:
49+
mixer.voice[0].level = 0.0
50+
prop_servo.throttle = 0.0
51+
else:
52+
prop_servo.throttle = 0.5
53+
mixer.voice[0].level = 0.5
54+
if ticks_diff(ticks_ms(), clock) >= prop_time:
55+
servo_move = False
56+
if lis3dh.shake(shake_threshold=20):
57+
servo_move = True
58+
clock = ticks_ms()
59+
clock = ticks_add(clock, prop_time)

Dune_Thumper/dune_thumper_sfx.wav

41.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)