Hardware Reference
In-Depth Information
5.
Next, add one last line of code beneath the
while
loop:
while True:
#
button = input(“Hit a button “)
if GPIO.input(PLAY_BUTTON):
print(“Pressed play button”)
if mlplayer.is_playing():
mlplayer.pause()
else:
mlplayer.play()
elif GPIO.input(STOP_BUTTON):
print(“Pressed stop button”)
mlplayer.stop()
random.shuffle(files)
medialist = vlc.MediaList(files)
mlplayer.set_media_list(medialist)
elif GPIO.input(BACK_BUTTON):
print(“Pressed back button”)
mlplayer.previous()
elif GPIO.input(FORWARD_BUTTON):
print(“Pressed forward button”)
mlplayer.next()
#
else:
#
print(“Unrecognised input”)
time.sleep(0.3)
lcd.scrollDisplayLeft()
he
while
loop is repeated roughly every 0.3 seconds, so the LCD screen scrolls
that often. his means that you can read artist and track names that are longer
than the LCD screen and it scrolls at a pleasantly readable speed using
lcd.
scrollDisplayLeft()
.
6.
Save this ile as
jukebox3.py
inside your
Documents
directory, by clicking on
File
➜
Save As and navigating to
Documents
inside
/home/pi
.
To run your inal jukebox program, open LXTerminal and navigate to your
Documents
folder using the command:
cd Documents
hen type the following command:
sudo python3 jukebox3.py
Press your jukebox buttons and check to see if the MP3 metadata is now being dis-
played on the LCD screen and whether it changes when you move between tracks
using the buttons (Figure 9-10). You may see some warnings but you can ignore them.