所以,我的目标是这样:
按下按钮,LED亮起并播放视频。
视频播放完后,LED和视频必须自动关闭。另外,在播放视频时,可以通过手动按下按钮来关闭LED和视频。
此刻,当我放置10秒的延迟时,LED将在那10秒钟内点亮。否则,LED将根本不会点亮。另外,有时会提示“ omxplayer.bin:未找到进程”。有时候,当我取消睡眠时,视频将无法播放。
GPIO.setmode(GPIO.BCM)
button1=17 #pin for button
LED1=18 #pin for LED
GPIO.setup(button1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(LED1, GPIO.OUT)
BS1=False #button state
last_state1 = True
input_state1 = True
player = False #video player state
while(1):
#Read states of input
input_state1 = GPIO.input(button1)
#If GPIO(17) is shorted to Ground/ When the button is pressed.
if input_state1 != last_state1:
if GPIO.input(button1)==0:
print ("LED ON")
if BS1 ==False:
GPIO.output(LED1,True) #turn on LED
BS1=True
elif (player and not input_state1):
print(player)
print(input_state1)
os.system('killall omxplayer.bin')
omxc = Popen(['omxplayer', '-b', movie1])
print ("Killall omxplayer")
player = True
elif not input_state1:
omxc = Popen(['omxplayer', '-b', movie1])
print ("Video Plays")
player = True
sleep(10)
else:
os.system('killall omxplayer.bin')
player = False
print ("Video Stops")
GPIO.output(LED1,False)
BS1=False
print ("LED OFF")
sleep(.5)
#Set last_input states
last_state1 = input_state1
GPIO.cleanup()