Skip to content

Commit 942f6cc

Browse files
committed
update crickit
1 parent 6b5c5d4 commit 942f6cc

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

Crickit_Sparky_Automaton/code.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
import os
22
import time
33
import random
4-
import audioio
5-
from digitalio import DigitalInOut, Direction
6-
from adafruit_seesaw.seesaw import Seesaw
7-
from adafruit_seesaw.pwmout import PWMOut
8-
from adafruit_motor import servo
9-
from busio import I2C
104
import board
5+
import audioio
6+
from adafruit_crickit import crickit
117

8+
# Sparky automaton
9+
10+
# Find all Wave files on the storage
1211
wavefiles = [file for file in os.listdir("/")
1312
if (file.endswith(".wav") and not file.startswith("._"))]
1413
print("Audio files found: ", wavefiles)
1514

16-
# Create seesaw object
17-
i2c = I2C(board.SCL, board.SDA)
18-
seesaw = Seesaw(i2c)
19-
20-
led = DigitalInOut(board.D13)
21-
led.direction = Direction.OUTPUT
15+
# mouth servo
16+
mouth_servo = crickit.servo_1
17+
# TowerPro servos like 500/2500 pulsewidths
18+
mouth_servo.set_pulse_width_range(min_pulse=500, max_pulse=2500)
2219

2320
# Servo angles
2421
MOUTH_START = 100
2522
MOUTH_END = 90
2623

27-
# 17 is labeled SERVO 1 on CRICKIT
28-
pwm = PWMOut(seesaw, 17)
29-
# must be 50 cannot change
30-
pwm.frequency = 50
31-
my_servo = servo.Servo(pwm)
32-
# Starting servo locations
33-
my_servo.angle = MOUTH_START
24+
# Starting servo location
25+
mouth_servo.angle = MOUTH_START
3426

3527
# Audio playback object and helper to play a full file
3628
a = audioio.AudioOut(board.A0)
3729

30+
# Play a wave file and move the mouth while its playing!
3831
def play_file(wavfile):
3932
print("Playing", wavfile)
4033
with open(wavfile, "rb") as f:
4134
wav = audioio.WaveFile(f)
4235
a.play(wav)
43-
while a.playing:
44-
my_servo.angle = MOUTH_END
36+
while a.playing: # turn servos, motors, etc. during playback
37+
mouth_servo.angle = MOUTH_END
4538
time.sleep(0.15)
46-
my_servo.angle = MOUTH_START
39+
mouth_servo.angle = MOUTH_START
4740
time.sleep(0.15)
4841

4942
while True:
43+
# Play a random quip
5044
play_file(random.choice(wavefiles))
45+
# then hang out for a few seconds
5146
time.sleep(3)

0 commit comments

Comments
 (0)