I have a Python 3 script that monitors a GPIO PIN on a Raspberry Pi.
The pin's value is returning 1 as expected using the following methodology:
io.setMode(io.BOARD)
b_pin = 40
b_status = 0
pin_value = int(io.input(b_pin))
print('pin_value['+str(pin_value)+']')
which prints to the console:
pin_value[1]
However, testing this in an if statement violates the elif condition:
if(pin_value == 1):
if(b_status != 0):
print('status open ['+str(pin_value)+'] ['+str(b_status)+']')
b_status = 0
elif(pin_value == 0):
if(b_status != 1):
print('status closed ['+str(pin_value)+'] ['+str(b_status)+']')
b_status = 1
which prints the resulting into IDLE console:
status closed [1] [0]
which violates the condition
elif(pin_value == 0):
What am I not understanding about Python if statements?
Aucun commentaire:
Enregistrer un commentaire