Hardware Reference
In-Depth Information
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)
Detecting GPIO input here uses the same methods as you used in Adventure 8;
you just check each of the GPIO's to see if it is connected to 3.3V (a logic high) or
connected to ground (a logic low). You want to add a sleep for a short time
(0.3 seconds) at the end, otherwise the same press might register multiple times.
When a mechanical switch is pressed, it “bounces” between logical high and low
which would be read as multiple presses. Here you are “debouncing” it by ignor-
ing changes that happen just after pressing the button.
5. Save this ile as jukebox2.py inside your Documents directory.
6. It is now time to test to see if your code works with your buttons. However, you
need to run this program as the super user by using sudo , exactly as you did in
Adventure 8 when you programmed the Raspberry Pi GPIO. To run your adapted
jukebox program, open LXTerminal, and navigate to your Documents folder
using the command:
cd Documents
hen type the following command:
sudo python3 jukebox2.py
Now press your jukebox buttons. Is everything working as you want it to work?
Part Four: Displaying Jukebox
Information on the LCD screen
Right at the start of this big project, you connected an LCD screen to a breadboard and
wired it to work using some adapted test code from Adafruit. Since then, you've pretty
much ignored the display. It's time to use the LCD screen to output information about
the MP3 ile that is being played—the name of the artist, the name of the track and
the name of the album. hat information comes from the metadata stored within the
MP3 ile.
Search WWH ::




Custom Search