Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5251

Other projects • How can I disable GPIO button presses while video is played?

$
0
0
I have this project where I am making a sort of space ship command panel for use in the kindergarten I work in, where I aim to integrate a Raspberry Pi in the kids' play. I use buttons to execute various videos through VLC (cvlc) on a 10.1" display. One button starts a countdown, one starts a video of a space shuttle rocket taking off, etc. Now, the problem I am having is that if I do what kids do and press all of the buttons without any sort of patience or restraint, the whole system freezes up. So what I am looking for is a way to disable all my buttons while the chosen video is played. Does anyone have any pointers on how I could do that?

The python code I am working with right now looks like this:

Code:

import RPi.GPIO as GPIOimport osimport sysfrom subprocess import PopenGPIO.setmode(GPIO.BCM)GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)movie1 = ("/home/user/planets/Countdown.mp4")movie2 = ("/home/user/planets/Take-Off.mp4")movie3 = ("/home/user/planets/Mars.mp4")movie4 = ("/home/user/planets/Galaxies.mp4")last_state1 = Truelast_state2 = Truelast_state3 = Truelast_state4 = Trueinput_state1 = Trueinput_state2 = Trueinput_state3 = Trueinput_state4 = True#quit_video = Trueplayer = Falsewhile True:    #Read states of inputs    input_state1 = GPIO.input(22)    input_state2 = GPIO.input(23)    input_state3 = GPIO.input(24)    input_state4 = GPIO.input(27)    #If GPIO(22) is shorted to Ground    if input_state1 != last_state1:        if (player and not input_state1):            os.system('killall vlc')            omxc = Popen(['cvlc', movie1])            player = True        elif not input_state1:            omxc = Popen(['cvlc', movie1])            player = True    #If GPIO(23) is shorted to Ground    if input_state2 != last_state2:        if (player and not input_state2):            os.system('killall vlc')            omxc = Popen(['cvlc', movie2])            player = True        elif not input_state2:            omxc = Popen(['cvlc', movie2])            player = True    #If GPIO(24) is shorted to Ground    if input_state3 != last_state3:        if (player and not input_state3):            os.system('killall vlc')            omxc = Popen(['cvlc', movie3])            player = True        elif not input_state3:            omxc = Popen(['cvlc', movie3])            player = True    #If GPIO(27) is shorted to Ground    if input_state4 != last_state4:        if (player and not input_state4):            os.system('killall vlc')            omxc = Popen(['cvlc', movie4])            player = True        elif not input_state4:            omxc = Popen(['cvlc', movie4])            player = True    #If omxplayer is running and GIOP(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 vlc.bin')#        player = False    #Set last_input states    last_state1 = input_state1    last_state2 = input_state2    last_state3 = input_state3    last_state4 = input_state4
Please disregard the parts commented out, as those are leftovers from an old script I found online that I have adapted for my use case and which was based on the outdated omxplayer instead of vlc.

Statistics: Posted by stian — Thu Sep 26, 2024 10:27 pm



Viewing all articles
Browse latest Browse all 5251

Trending Articles