Skip to content

Instantly share code, notes, and snippets.

@TheRealEdDawson
Last active August 6, 2019 03:05
Show Gist options
  • Save TheRealEdDawson/5242320 to your computer and use it in GitHub Desktop.
Save TheRealEdDawson/5242320 to your computer and use it in GitHub Desktop.
Rapsberry Pi MP3 Buttons
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)
while True:
if ( GPIO.input(23) == False ):
os.system('mpg321 Typing.mp3 &')
if ( GPIO.input(24) == False ):
os.system('mpg321 WaterRunning.mp3 &')
if ( GPIO.input(25)== False ):
os.system('mpg321 DoorClose.mp3 &')
sleep(0.1);
@TheRealEdDawson
Copy link
Author

For toys or game type projects, play a sound (MP3 file) when you press a button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment