简体   繁体   中英

Python GPIO raspberry pi

So bassicaly the user will press the picture_pin buton first, then this calls the picture_taking() function which then it should stop and wait for either (Accept_Pin or Decline_Pin) buttons to be pressed, it should not let the user to continue unless a selection is made. so when the user makes his/her selection then it go back and wait for the picture_pin button. at this stage the Accept_Pin and Decline_Pin should have no affect at all.

I have a python program that waits for a button press from the user then it runs a function to do its thing. what I would like to accomplish is, in that function I would like to also wait for another button press.

(Main.py)
----etc
## PICTURE FUNCTION ##
def picture_taking():
    .....etc
        returnvalue = subprocess.check_output("sudo ./" + config.layout + ".sh",      shell=True) 
    GPIO.wait_for_edge(Accept_pin, GPIO.FALLING)  
    GPIO.wait_for_edge(Decline_Pin, GPIO.FALLING)
    pad1alreadyPressed = False
    pad4alreadyPressed = False 

    while True:  
        pad1pressed = not GPIO.input(Accept_pin) 
        pad4pressed = not GPIO.input(Decline_Pin)
        if pad1pressed and not pad1alreadyPressed: 
           print "Accepted photo:" + str(returnvalue) 
           pad1alreadyPressed = pad1pressed 

        if pad4pressed and not pad4alreadyPressed: 
           print "Declined photo:" + str(returnvalue) 
           pad4alreadyPressed = pad4pressed   
(This here is my Main Program)
#Main section

while True:
        time.sleep(0.2)
            #camera.hflip = false
            camera.shutter_speed = 2000000000
            camera.exposure_mode = 'off'
            #camera.iso = 1000
            camera.preview_fullscreen = True
            camera.preview_alpha = 150
            camera.start_preview()
            GPIO.wait_for_edge(picture_pin, GPIO.FALLING)
            picture_taking()

So in the picture_taking() function I would like to ask the user if they accept this picture or not
if they press button (GPIO 19) then they accept or (GPIO 6) as Decline

after they do there selection the program should go back and wait for the main button to select below. and these two buttons should only be selectable inside the function.

I tried this in the Picture_taking() function

when I make the selection it only accepts the "Decline_pin" button, but after I press the "Decline button" then it reads "Accept button".
The other issue is that it does not go back and wait for the Main button "picture_pin" to be pressed. it seems to be stuck here and not exiting.

I am not sure if this is something to do with Indent stuff in Python.

Thank you.

(This should be a comment, not an answer but I don't have reputation 50 yet).

Is this your actual code? I can't understand how it ever returns from the while True: clause in picture_taking() . I'd think you'd need to have something like

while (!(pad1alreadyPressed or pad4alreadyPressed)):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM