Skip to content

Commit 56ba6b1

Browse files
authored
Merge pull request #2833 from adafruit/soundbox-update
update soundbox code and sounds
2 parents ad042d2 + 8de5b7a commit 56ba6b1

23 files changed

+10
-8
lines changed

CircuitPython_Sound_Box_2/code.py

100644100755
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import adafruit_lis3dh
1515

1616
from rainbowio import colorwheel
17-
hue = 0
17+
1818
# enable external power pin
1919
# provides power to the external components
2020
external_power = DigitalInOut(board.EXTERNAL_POWER)
@@ -25,6 +25,10 @@
2525
num_pixels = 24
2626
pixels = neopixel.NeoPixel(board.EXTERNAL_NEOPIXELS, num_pixels, brightness=0.4, auto_write=True)
2727

28+
delta_hue = 256//num_pixels
29+
speed = 10 # higher numbers = faster rainbow spinning
30+
i=0
31+
2832
# external button
2933
switch = keypad.Keys((board.EXTERNAL_BUTTON,), value_when_pressed=False, pull=True)
3034

@@ -58,7 +62,6 @@
5862
num_shakes = len(shake_wavs)
5963
wav_index = 0
6064

61-
6265
def open_audio(num, wavs):
6366
n = wavs[num]
6467
f = open(n, "rb")
@@ -83,18 +86,17 @@ def open_audio(num, wavs):
8386
pixels.fill(color['color'])
8487
else:
8588
pass
86-
time.sleep(.7)
89+
time.sleep(1)
8790
pixels.fill((0, 0, 0))
8891
print('pressed')
8992
if event.released:
9093
pass
9194
if lis3dh.shake(shake_threshold=12):
9295
wave, wave_name = open_audio(random.randint(0, num_shakes - 1), shake_wavs)
9396
audio.play(wave)
94-
for i in range(num_pixels):
95-
pixels[i] = colorwheel(hue)
96-
hue = (hue + 30) % 256
97-
print(hue)
98-
time.sleep(.7)
97+
for l in range(len(pixels)):
98+
pixels[l] = colorwheel( int(i*speed + l * delta_hue) % 255 )
99+
pixels.show()
100+
time.sleep(1)
99101
pixels.fill((0, 0, 0))
100102
print('shake')
-35.9 KB
Binary file not shown.
91.2 KB
Binary file not shown.
-21.6 KB
Binary file not shown.
106 KB
Binary file not shown.
-21.6 KB
Binary file not shown.
122 KB
Binary file not shown.
-16.2 KB
Binary file not shown.
91.2 KB
Binary file not shown.
-41.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)