Created
August 17, 2015 05:12
-
-
Save valbeat/a84701c02fc81c730a6a to your computer and use it in GitHub Desktop.
omxplayer movie changer with GPIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
import subprocess | |
import wiringpi2 | |
from time import sleep | |
# IO | |
OUTPUT = 1 | |
INPUT = 0 | |
HIGH = 1 | |
LOW = 0 | |
# pin number settings | |
BUTTON1 = 2 | |
BUTTON2 = 3 | |
BUTTON3 = 4 | |
io = wiringpi2 | |
io.wiringPiSetupGpio() | |
io.pinMode(BUTTON1,INPUT) | |
io.pinMode(BUTTON2,INPUT) | |
io.pinMode(BUTTON3,INPUT) | |
playProcess = None | |
def play_movie(file): | |
print file | |
cmd = "omxplayer " + file | |
global playProcess | |
if playProcess is not None: | |
try: | |
playProcess.stdin.write('q') | |
playProcess.terminate() | |
playProcess.wait() | |
except EnvironmentError as e: | |
print e | |
else: | |
playProcess = None | |
playProcess = subprocess.Popen(cmd.strip().split(" "), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) | |
while 1: | |
if io.digitalRead(BUTTON1) == 0: | |
play_movie('movie1.mov') | |
if io.digitalRead(BUTTON2) == 0: | |
play_movie('movie2.mov') | |
if io.digitalRead(BUTTON3) == 0: | |
play_movie('movie3.mov') | |
sleep(.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment