User Manual

You may want to have the audio track match to motion or events in your robot. To do that you can do some tricks with
time.monotonic() . That's our way of know true time passage, it returns a floating point (fractional) value in seconds.
Note its hard to get the exact precise second so use > and < rather than checking for = equality because minute
variations will make it hard to get the time delta exactly when it occurs.
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
import audioio
import board
import time
# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)
# what counts as a 'touch'
CAPTOUCH_THRESH = 500
wavfile = "howto.wav"
f = open(wavfile, "rb")
wav = audioio.WaveFile(f)
a = audioio.AudioOut(board.A0)
a.play(wav)
t = time.monotonic() # this is the time when we started
# wait until we're at timecode 5.5 seconds into the audio
while time.monotonic() - t < 5.5:
pass
a.pause() # pause the audio
print("Waiting for Capacitive touch!")
while seesaw.touch_read(0) < CAPTOUCH_THRESH:
pass
a.resume() # resume the audio
# You can now do all sorts of stuff here while the audio plays
# such as move servos, motors, read sensors...
# Or wait for the audio to finish playing:
while a.playing:
pass
print("Done!")
© Adafruit Industries
https://learn.adafruit.com/adafruit-crickit-creative-robotic-interactive-
construction-kit
Page 117 of 201