I'm trying to setup a switch on a breakout board which, upon flicking the switch, will allow me to play a short mp3, then loop a second mp3 until I switch it off. When I do so, I want it to play a third mp3 (this is basically a siren starting up looping then shutting down). I can play mp3s using a push button but don't know how to use the switch, any help?
This is the current python script I'm using
import pygame.mixer import RPi.GPIO as GPIO from time import sleep from sys import exit GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN) GPIO.setup(24, GPIO.IN) GPIO.setup(25, GPIO.IN) pygame.mixer.init(48000, -16, 1, 1024) sndA = pygame.mixer.Sound("buzzer.wav") sndB = pygame.mixer.Sound("clap.wav") sndC = pygame.mixer.Sound("laugh.wav") soundChannelA = pygame.mixer.Channel(1) soundChannelB = pygame.mixer.Channel(2) soundChannelC = pygame.mixer.Channel(3) print "Soundboard Ready." while True: try: if (GPIO.input(23) == True): soundChannelA.play(sndA) if (GPIO.input(24) == True): soundChannelB.play(sndB) if (GPIO.input(25) == True): soundChannelC.play(sndC) sleep(.01) except KeyboardInterrupt: exit()