Skip to content

Commit 43a064c

Browse files
authored
Merge pull request #782 from adafruit/master-sword-random
Master Sword SFX Update
2 parents 8022d3f + 3e509c7 commit 43a064c

11 files changed

Lines changed: 27 additions & 10 deletions

File tree

Propmaker_Master_Sword/code.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111

1212
import time
13+
import random
1314
import digitalio
1415
import audioio
1516
import busio
@@ -19,24 +20,24 @@
1920

2021
# CUSTOMISE COLORS HERE:
2122
COLOR = (0, 120, 120) # Default idle is light blue
22-
ALT_COLOR = (255, 255, 255) # hit color is bright white
23+
ALT_COLOR = (255, 50, 0) # hit color is orange
2324

2425
# CUSTOMISE IDLE PULSE SPEED HERE: 0 is fast, above 0 slows down
25-
IDLE_PULSE_SPEED = 0.05 # Default is 0.1 seconds
26-
SWING_BLAST_SPEED = 0.01
26+
IDLE_PULSE_SPEED = 0 # Default is 0 seconds
27+
SWING_BLAST_SPEED = 0.007
2728

2829
# CUSTOMISE BRIGHTNESS HERE: must be a number between 0 and 1
29-
IDLE_PULSE_BRIGHTNESS_MIN = 0.3 # Default minimum idle pulse brightness
30-
IDLE_PULSE_BRIGHTNESS_MAX = 0.6 # Default maximum idle pulse brightness
30+
IDLE_PULSE_BRIGHTNESS_MIN = 0.2 # Default minimum idle pulse brightness
31+
IDLE_PULSE_BRIGHTNESS_MAX = 1 # Default maximum idle pulse brightness
3132

3233
# CUSTOMISE SENSITIVITY HERE: smaller numbers = more sensitive to motion
33-
HIT_THRESHOLD = 500
34-
SWING_THRESHOLD = 125
34+
HIT_THRESHOLD = 250
35+
SWING_THRESHOLD = 150
3536

3637
# Set to the length in seconds of the "on.wav" file
3738
POWER_ON_SOUND_DURATION = 1.7
3839

39-
NUM_PIXELS = 30 # Number of pixels used in project
40+
NUM_PIXELS = 83 # Number of pixels used in project
4041
NEOPIXEL_PIN = board.D5
4142
POWER_PIN = board.D10
4243

@@ -120,6 +121,22 @@ def mix(color_1, color_2, weight_2):
120121
int(color_1[1] * weight_1 + color_2[1] * weight_2),
121122
int(color_1[2] * weight_1 + color_2[2] * weight_2))
122123

124+
# List of swing wav files without the .wav in the name for use with play_wav()
125+
swing_sounds = [
126+
'swing1',
127+
'swing2',
128+
'swing3',
129+
'swing4',
130+
]
131+
132+
# List of hit wav files without the .wav in the name for use with play_wav()
133+
hit_sounds = [
134+
'hit1',
135+
'hit2',
136+
'hit3',
137+
'hit4',
138+
]
139+
123140

124141
mode = 0 # Initial mode = OFF
125142

@@ -150,12 +167,12 @@ def mix(color_1, color_2, weight_2):
150167
# comparing thresholds...use squared values instead.)
151168
if accel_total > HIT_THRESHOLD: # Large acceleration = HIT
152169
TRIGGER_TIME = time.monotonic() # Save initial time of hit
153-
play_wav('hit') # Start playing 'hit' sound
170+
play_wav(random.choice(hit_sounds)) # Start playing 'hit' sound
154171
COLOR_ACTIVE = COLOR_HIT # Set color to fade from
155172
mode = 3 # HIT mode
156173
elif mode == 1 and accel_total > SWING_THRESHOLD: # Mild = SWING
157174
TRIGGER_TIME = time.monotonic() # Save initial time of swing
158-
play_wav('swing') # Start playing 'swing' sound
175+
play_wav(random.choice(swing_sounds)) # Randomly choose from available swing sounds
159176
# make a larson scanner animation_time
160177
strip_backup = strip[0:-1]
161178
for p in range(-1, len(strip)):
-94.8 KB
Binary file not shown.
31.6 KB
Binary file not shown.
33 KB
Binary file not shown.
40.2 KB
Binary file not shown.
38.8 KB
Binary file not shown.
-34.5 KB
Binary file not shown.
38.8 KB
Binary file not shown.
31.6 KB
Binary file not shown.
25.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)