I'm building a jukebox controlled by the rpi, and created some python code to control it (I'm a beginner here).
The way it's supposed to work is that when a button is pressed (there are 7 of them), the rpi will play an mp3 (using mpg321, but any other format is fine too) and a few leds will light up (that part is yet to be written). The thing is, once a song is played there shouldn't be an option to start another (i.e., the buttons doesn't work), but once a song has ended the user can pick any song to play next.
Would be glad to have any advice with this, here is the code I got so far (only allows one song to play once each time, no loop).
Thanks!
Code: Select all
#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# Buttons:
GPIO.setup(15, GPIO.IN)
GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.IN)
GPIO.setup(21, GPIO.IN)
GPIO.setup(22, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
while True:
if ( GPIO.input(15) == False ):
os.system('mpg321 1.mp3 &')
break
elif ( GPIO.input(17) == False ):
os.system('mpg321 2.mp3 &')
break
elif ( GPIO.input(18) == False ):
os.system('mpg321 3.mp3 &')
break
elif ( GPIO.input(21) == False ):
os.system('mpg321 4.mp3 &')
break
elif ( GPIO.input(22) == False ):
os.system('mpg321 5.mp3 &')
break
elif ( GPIO.input(23) == False ):
os.system('mpg321 6.mp3 &')
break
elif ( GPIO.input(24) == False ):
os.system('mpg321 7.mp3 &')
break
sleep(0.1);