updated RPi.GPIO code to python3 with proper syntax for travis, using omxplayer on all code

This commit is contained in:
Mikey Sklar 2018-12-06 16:41:23 -07:00
parent 78d0dace5e
commit b5dbf7c62c
2 changed files with 22 additions and 26 deletions

View file

@ -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)

View file

@ -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);
sleep(0.25)