Skip to content

audioio timers in use - CP3.0 #850

@jerryneedell

Description

@jerryneedell

on CPX with current master
The following code executes 3 times then works on the 4th try:

buttonA = DigitalInOut(board.BUTTON_A)
buttonA.direction = Direction.INPUT
buttonA.pull = Pull.DOWN

buttonB = DigitalInOut(board.BUTTON_B)
buttonB.direction = Direction.INPUT
buttonB.pull = Pull.DOWN

# The two files assigned to buttons A & B
audiofiles = ["rimshot.wav", "laugh.wav"]

def play_file(filename):
    print("playing file "+filename)
    with open(filename,"rb") as f:
        wav = audioio.WaveFile(f)
        with audioio.AudioOut(board.A0) as a:
            a.play(wav)
            while a.playing:
                pass
            print("finished")
while True:
    if buttonA.value:
        play_file(audiofiles[0])
    if buttonB.value:
        play_file(audiofiles[1])

works 3 times then fails:

Adafruit CircuitPython 3.0.0-alpha.6-143-g990da6d on 2018-05-19; Adafruit CircuitPlayground Express with samd21g18
>>> 
>>> 
>>> 
>>> import audio
playing file rimshot.wav
finished
playing file laugh.wav
finished
playing file rimshot.wav
finished
playing file laugh.wav
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "audio.py", line 35, in <module>
  File "audio.py", line 30, in play_file
  File "audio.py", line 26, in play_file
RuntimeError: All timers in use
>>> 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions