Skip to content

Commit 4084392

Browse files
authored
Add files via upload
1 parent 349a525 commit 4084392

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Crickits/HAL-9000/code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import os
6+
import random
7+
import time
8+
import board
9+
import audioio
10+
import audiocore
11+
from adafruit_crickit import crickit
12+
13+
# Hal button-and-voice example
14+
15+
# Button connected to Signal pin #1 & ground:
16+
BUTTON = crickit.SIGNAL1
17+
crickit.seesaw.pin_mode(BUTTON, crickit.seesaw.INPUT_PULLUP)
18+
19+
# LED connected to 5V & Drive pin #1:
20+
LED = crickit.drive_1
21+
LED.duty_cycle = 65535
22+
23+
# Find all Wave files in CIRCUITPY storage:
24+
WAVEFILES = [file for file in os.listdir("/")
25+
if (file.endswith(".wav") and not file.startswith("._"))]
26+
print("Audio files found:", WAVEFILES)
27+
28+
# Audio playback object:
29+
AUDIO = audioio.AudioOut(board.A0)
30+
31+
# Function to play a wave file in its entirety:
32+
def play_file(wavfile):
33+
print("Playing", wavfile)
34+
with open(wavfile, "rb") as f:
35+
wav = audiocore.WaveFile(f)
36+
AUDIO.play(wav)
37+
while AUDIO.playing:
38+
LED.duty_cycle = random.randint(5000, 30000)
39+
time.sleep(0.1)
40+
LED.duty_cycle = 65535
41+
42+
while True:
43+
if not crickit.seesaw.digital_read(BUTTON):
44+
# Play a random wave file
45+
play_file(random.choice(WAVEFILES))
46+
# Then wait for button to be released
47+
while not crickit.seesaw.digital_read(BUTTON):
48+
continue

0 commit comments

Comments
 (0)