Hardware Reference
In-Depth Information
9.
Now add two more buttons to this loop to skip back and forward. Be careful of
the indentation of your code, as you are continuing the irst conditional (see
Figure 9-7). Directly underneath the last line type the following:
elif button == “3”:
print(“Pressed back button”)
mlplayer.previous()
elif button == “4”:
print(“Pessed forward button”)
mlplayer.next()
else:
print(“Unrecognised input”)
10.
Save your ile as
jukebox1.py
inside your
Documents
directory, by clicking
File
➜
Save As and navigating to
Documents
inside
/home/pi
.
11.
Finally, test to see if your code works by clicking Run
➜
Run Module, or from the
LXTerminal by changing to the
Documents
directory and typing
python3
jukebox1.py
FIGURE 9-7
Writing a jukebox program in Python IDLE 3