update soundbox code and sounds

updating soundbox code and sounds
This commit is contained in:
Noe Ruiz 2024-06-10 15:40:43 -04:00
parent ad042d2498
commit 8de5b7a9fe
23 changed files with 10 additions and 8 deletions

18
CircuitPython_Sound_Box_2/code.py Normal file → Executable file
View file

@ -14,7 +14,7 @@ import keypad
import adafruit_lis3dh import adafruit_lis3dh
from rainbowio import colorwheel from rainbowio import colorwheel
hue = 0
# enable external power pin # enable external power pin
# provides power to the external components # provides power to the external components
external_power = DigitalInOut(board.EXTERNAL_POWER) external_power = DigitalInOut(board.EXTERNAL_POWER)
@ -25,6 +25,10 @@ external_power.value = True
num_pixels = 24 num_pixels = 24
pixels = neopixel.NeoPixel(board.EXTERNAL_NEOPIXELS, num_pixels, brightness=0.4, auto_write=True) pixels = neopixel.NeoPixel(board.EXTERNAL_NEOPIXELS, num_pixels, brightness=0.4, auto_write=True)
delta_hue = 256//num_pixels
speed = 10 # higher numbers = faster rainbow spinning
i=0
# external button # external button
switch = keypad.Keys((board.EXTERNAL_BUTTON,), value_when_pressed=False, pull=True) switch = keypad.Keys((board.EXTERNAL_BUTTON,), value_when_pressed=False, pull=True)
@ -58,7 +62,6 @@ num_colors = len(color_wavs)
num_shakes = len(shake_wavs) num_shakes = len(shake_wavs)
wav_index = 0 wav_index = 0
def open_audio(num, wavs): def open_audio(num, wavs):
n = wavs[num] n = wavs[num]
f = open(n, "rb") f = open(n, "rb")
@ -83,7 +86,7 @@ while True:
pixels.fill(color['color']) pixels.fill(color['color'])
else: else:
pass pass
time.sleep(.7) time.sleep(1)
pixels.fill((0, 0, 0)) pixels.fill((0, 0, 0))
print('pressed') print('pressed')
if event.released: if event.released:
@ -91,10 +94,9 @@ while True:
if lis3dh.shake(shake_threshold=12): if lis3dh.shake(shake_threshold=12):
wave, wave_name = open_audio(random.randint(0, num_shakes - 1), shake_wavs) wave, wave_name = open_audio(random.randint(0, num_shakes - 1), shake_wavs)
audio.play(wave) audio.play(wave)
for i in range(num_pixels): for l in range(len(pixels)):
pixels[i] = colorwheel(hue) pixels[l] = colorwheel( int(i*speed + l * delta_hue) % 255 )
hue = (hue + 30) % 256 pixels.show()
print(hue) time.sleep(1)
time.sleep(.7)
pixels.fill((0, 0, 0)) pixels.fill((0, 0, 0))
print('shake') print('shake')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.