lundi 22 avril 2019

While conditions with an and inside

Hi I am trying to run the following code to access a Raspberry Pi in a follow the line robotic car The goal is can these while if elif work ?

i tried to read about it but still not finding the binding and in double cases

# First we setup pins as Inputs and Outputs
# for controlling the direction of the Wheels
    GPIO.setup(3,GPIO.IN)
    GPIO.setup(5,GPIO.IN)
    GPIO.setup(7,GPIO.OUT)
    GPIO.setup(8,GPIO.OUT)
    GPIO.setup(11,GPIO.OUT)
    GPIO.setup(12,GPIO.OUT)

    while (1):
        if (GPIO.input(3) == True and GPIO.input(5) == True):
            GPIO.output(7,GPIO.HIGH)
            GPIO.output(8,GPIO.LOW)
            GPIO.output(11,GPIO.HIGH)
            GPIO.output(12,GPIO.LOW)


        elif (GPIO.input(15) == False) and (GPIO.input(5) == True):      
            GPIO.output(7,GPIO.HIGH)    
            GPIO.output(8,GPIO.HIGH)   
            GPIO.output(11,GPIO.HIGH)
            GPIO.output(12,GPIO.LOW)

        elif(GPIO.input(3) == True) and (GPIO.input(5) == False):         

            GPIO.output(7,GPIO.HIGH)      
            GPIO.output(8,GPIO.LOW)     
            GPIO.output(11,GPIO.HIGH)    
            GPIO.output(12,GPIO.HIGH)  

        elif(GPIO.input(3)==False) and (GPIO.input(5) == False): 
              GPIO.output(7,GPIO.HIGH)   
              GPIO.output(8,GPIO.HIGH)   
              GPIO.output(11,GPIO.HIGH)     
              GPIO.output(12,GPIO.HIGH)     

Aucun commentaire:

Enregistrer un commentaire