Dartanan sams
Dartanan sams

Reputation: 45

if statement gone wrong

im trying to use a if statement to print if the led is on but the ide is ignoring the if statement and only doing whats outside it also ive tried using the gpiozero library but it reads the pins wrong i dont have any jumpers connected to pin 17 but its the only pin that turns the led on

from rpi.gpiozero import LED
import time
GPIO.setmode(GPIO.BOARD
GPIO.setup(11,GPIO.OUT)

for i in range(25):
    GPIO.OUTPUT(11,True)
    if GPIO.OUTPUT(11,True):
        print('LED is on')
    time.sleep(1)
    GPIO.OUTPUT(11,False)
    if GPIO.OUTPUT(11,False):
        print('LED is off')
    time.sleep(1)
GPIO.CLEANUP()

Upvotes: 0

Views: 118

Answers (1)

KYL3R
KYL3R

Reputation: 4073

You are setting the GPIO Pin in your if statement. You need to read it.

GPIO.Input Returns 0 if OFF or 1 if ON

So your code should look like this:

if GPIO.input(11):
    print('LED is on')

You can read about the usage in the docs under "Input".

Upvotes: 3

Related Questions