I’m wanting to make a standalone device that plays a .wav file when a button is pressed, using a pHATBEAT and a Pi Zero W. The simple Python 3 script I’ve written so far works fine when executed in IDLE, but if I try to run it from the command line I get silence, and a couple of random LEDs light on the pHAT. If I remove the button handlers and just run the bit that plays the sound file, it’s fine. I’m new to all this so it’s hopefully something simple!
import pygame import time import phatbeat import os pygame.init whistle = pygame.mixer.Sound("sounds/whistle.wav") @phatbeat.on(phatbeat.BTN_PLAYPAUSE) def playpause(pin): pygame.mixer.Sound.play(whistle) time.sleep(5) @phatbeat.on(phatbeat.BTN_ONOFF) def onoff(pin): os.system("sudo shutdown -h now")
Any ideas please?