Things used in this project

Hardware components:
12994 02
Raspberry Pi 1 Model B+
12002 04
Breadboard (generic)
11026 02
Jumper wires (generic)
Wifi Dongle
Keyboard and Mouse


Fritzing Layout


Code snippet #1Plain text
import Rpi.GPIO as GPIO
import sys
import os
from subprocess import Popen
Code snippet #2Plain text
Code snippet #3Plain text
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Code snippet #4Plain text
movie1 = ("/home/pi/Videos/movie1.mp4")
movie2 = ("/home/pi/Videos/movie2.mp4")
Code snippet #5Plain text
last_state1 = True
last_state2 = True

input_state1 = True
input_state2 = True

quit_video = True
Code snippet #6Plain text
while True:
	#Read states of inputs
	input_state1 = GPIO.input(17)
	input_state2 = GPIO.input(18)
	quite_video = GPIO.input(24)

	#If GPIO(17) is shorted to ground
	if input_state1 != last_state1:
		if (player and not input_state1):
			os.system('killall omxplayer.bin')
			omxc = Popen(['omxplayer', '-b', movie1])
			player = True
		elif not input_state1:
			omxc = Popen(['omxplayer', '-b', movie1])
			player = True
	#If GPIO(18) is shorted to ground
	elif input_state2 != last_state2:
		if (player and not input_state2):
			os.system('killall omxplayer.bin')
			omxc = Popen(['omxplayer', '-b', movie2])
			player = True
		elif not input_state2:
			omxc = Popen(['omxplayer', '-b', movie2])
			player = True

	#If omxplayer is running and GPIO(17) and GPIO(18) are NOT shorted to ground
	elif (player and input_state1 and input_state2):
		os.system('killall omxplayer.bin')
		player = False

	#GPIO(24) to close omxplayer manually - used during debug
	if quit_video == False:
		os.system('killall omxplayer.bin')
		player = False

	#Set last_input states
	last_state1 = input_state1
	last_state2 = input_state2
Code snippet #7Plain text
pi@raspberrypi:~$ python3


2 projects • 30 followers
Just a guy who plays around trying to find new ways to do things


Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog