timoinnewton
Posts: 1
Joined: Mon Oct 29, 2018 9:29 pm

gpio and keyboard input for gpio pins.

Fri Nov 02, 2018 1:34 am

Hi,
I'm rather new to Python and the pi. I was wanting to use both a gpio pin and a usb keyboard as inputs to control oxmplayer playback, but not necessary at the same time. I borrowed ThothLoki's instructable for gpio control of the oxmplayer. Would nesting an input from the keyboard inside an if statement looking for gpio input be an ok way to switch to keyboard from gpio? I was just hoping to first have the gpio shorted out before keyboard was going to work.

I got it to work, but it acts a little wonky at times. Video not starting at the beginning and enter key playing the video once when gpio pin not shorted.

Thanks for any input

The code I'm using.

Code: Select all

if input_state1 != last_state1:
                
                if (player and not input_state1):
                                key = input()
                #If GPIO(17) is shorted to ground
                if key == "5":
                                os.system('killall omxplayer.bin')
                                omxc = Popen(['omxplayer', '-b', movie1])
                                player = True
                                key = 0
                                print(key)
                elif not input_state1:
                                omxc = Popen(['omxplayer', '-b', movie1])
                                player = True

Return to “Python”