#hi David , I am Rishabh Garg From India :) #this is my code and i provided you my video Sample link here - https://youtu.be/LgkDJzYYiVg #please check this video first which was aim to make #i use Raspberry pi + GPIO(two input pins) + python #Everything is Fine and Sometimes it runs without any Code freeze #but sometimes the code freeze at time.sleep(0.5) line number 52 #this is a Dark base for me :( #i also use Threading which cause same error #Pleaseeeee David help meee :) #and please check that youtube link which helps to understand you the program import RPi.GPIO as GPIO import os import time import sys import subprocess from imp import reload global streamVideo import threading os.system("sudo fbi -T 2 -d /dev/fb0 -noverbose -a 13.jpg") before = False class TimerClass(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.event = threading.Event() def run(self): input1 = GPIO.input(23) input2 = GPIO.input(24) if(input1==False and input2==False and not self.event.is_set()): # os.system('killall omxplayer.bin') streamVideo = subprocess.Popen(['omxplayer', '-o', 'hdmi', 'intro.mp4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, close_fds=True) # time.sleep(0.5) before=True self.event.wait(1) def stop(self): self.event.set() GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18,GPIO.OUT) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) while True: GPIO.output(18,GPIO.HIGH) input1 = GPIO.input(23) input2 = GPIO.input(24) # try: tmr = TimerClass() tmr.start() time.sleep(0.5) if(input1==True): os.system('killall omxplayer.bin') while(input1): if GPIO.input(23)==False: tmr.stop() os.system('killall omxplayer.bin') break streamVideo = subprocess.Popen(['omxplayer', '-o', 'hdmi', '15.mp4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, close_fds=True) time.sleep(3.5) reload(time) if(input2==True): os.system('killall omxplayer.bin') while(input2): if GPIO.input(24)==False: tmr.stop() os.system('killall omxplayer.bin') break streamVideo = subprocess.Popen(['omxplayer', '-o', 'hdmi', '15.mp4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, close_fds=True) time.sleep(3.5) reload(time) tmr.stop() reload(time) # except: # print("Error: unable to start thread") GPIO.cleanup()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question