# code to play a wave file saved on the Pico microcontroller import machine from machine import SPI,Pin import utime import os import os as uos from wavePlayer import wavePlayer import wave #define the pin to the amp and speaker pwm = machine.PWM(machine.Pin(19)) #turn on the amplifier amp_shutdown_pin = machine.Pin(21, machine.Pin.OUT, machine.Pin.PULL_UP) amp_shutdown_pin.value(0) # code to check what files are on the Pico microcontroller in the "sounds" folder waveFolder= "/sounds" wavelist = [] # get a list of .wav files for i in os.listdir(waveFolder): if i.find(".wav")>=0: wavelist.append(waveFolder+"/"+i) elif i.find(".WAV")>=0: wavelist.append(waveFolder+"/"+i) if not wavelist : print("Warning NO '.wav' files") else: for i in wavelist: print(i) # play the R2D2 wav file from the pico flash memory player = wavePlayer() try: while True: # repeat this over and over until the keyboard shuts down the circuit player.play('/sounds/hello_neil_2.wav') # originally was /sounds/r2d2-taking-to-himself.wav except KeyboardInterrupt: player.stop() print("wave player terminated") #turn off the amplifier amp_shutdown_pin.value(1)