Hardware Reference
In-Depth Information
FIGURE 9-9
Completed wiring of Pi jukebox with buttons
Adapting Your Jukebox Program to
Include GPIO Buttons
With the physical buttons connected to the breadboard and Raspberry Pi GPIO pins,
you need to adapt the jukebox program code for them to work.
1.
Open
jukebox1.py
using Python IDLE 3 and edit the code to include the
parts highlighted in the following code:
import glob, random, sys, vlc,
time
import RPi.GPIO as GPIO
As well as the modules you imported earlier, you will need to import the
time
module so that you can use the
sleep
function in your code, and you need to
import
RPi.GPIO
so that you can set up the buttons for input in the code.
2.
he next part of the code remains the same:
if len(sys.argv) <= 1:
print(“Please specify a folder with mp3 files”)
sys.exit(1)
folder = sys.argv[1]
files = glob.glob(folder+”/*.mp3”)
if len(files) == 0:
print(“No mp3 files in directory”, folder, “..exiting”)
sys.exit(1)