Skip to content

Instantly share code, notes, and snippets.

@valbeat
Created August 18, 2015 10:16
Show Gist options
  • Save valbeat/6122af8786e2f8169db6 to your computer and use it in GitHub Desktop.
Save valbeat/6122af8786e2f8169db6 to your computer and use it in GitHub Desktop.
#!/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