diff --git a/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-audio-button.py b/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-audio-button.py index ec6ccfc03..dd773249e 100644 --- a/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-audio-button.py +++ b/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-audio-button.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os from time import sleep @@ -11,13 +9,13 @@ GPIO.setup(24, GPIO.IN) GPIO.setup(25, GPIO.IN) while True: - if (GPIO.input(23) == False): - os.system('mpg123 -q temple-bell.mp3 &') + if not GPIO.input(23): + os.system('omxplayer temple-bell.mp3 &') - if (GPIO.input(24) == False): - os.system('mpg123 -q temple-bell-bigger.mp3 &') + if not GPIO.input(24): + os.system('omxplayer temple-bell-bigger.mp3 &') - if (GPIO.input(25)== False): - os.system('mpg123 -q temple-bell-huge.mp3 &') + if not GPIO.input(25): + os.system('omxplayer temple-bell-huge.mp3 &') - sleep(0.1); + sleep(0.25) diff --git a/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-simple-jukebox.py b/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-simple-jukebox.py index 8443a9e11..eb1540f4a 100644 --- a/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-simple-jukebox.py +++ b/Playing_Sounds_and_Using_Buttons_with_Raspberry_Pi/RPi.GPIO-raspi-simple-jukebox.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - from os import listdir import subprocess from time import sleep @@ -13,29 +11,29 @@ GPIO.setup(25, GPIO.IN) mp3_files = [ f for f in listdir('.') if f[-4:] == '.mp3' ] -if not (len(mp3_files) > 0): - print "No mp3 files found!" +if not len(mp3_files) > 0: + print("No mp3 files found!") -print '--- Available mp3 files ---' -print mp3_files -print '--- Press button #1 to select mp3, button #2 to play current. ---' +print('--- Available mp3 files ---') +print(mp3_files) +print('--- Press button #1 to select mp3, button #2 to play current. ---') index = 0 while True: - if (GPIO.input(23) == False): + if not GPIO.input(23): index += 1 if index >= len(mp3_files): index = 0 - print "--- " + mp3_files[index] + " ---" + print("--- " + mp3_files[index] + " ---") - if (GPIO.input(24) == False): - subprocess.Popen(['mpg123', mp3_files[index]]) - print '--- Playing ' + mp3_files[index] + ' ---' - print '--- Press button #3 to clear playing mp3s. ---' + if not GPIO.input(24): + subprocess.Popen(['omxplayer', mp3_files[index]]) + print('--- Playing ' + mp3_files[index] + ' ---') + print('--- Press button #3 to clear playing mp3s. ---') sleep(1) - if (GPIO.input(25) == False): - subprocess.call(['killall', 'mpg123']) - print '--- Cleared all existing mp3s. ---' + if not GPIO.input(25): + subprocess.call(['killall', 'omxplayer']) + print('--- Cleared all existing mp3s. ---') - sleep(0.1); \ No newline at end of file + sleep(0.25)