0

I recently bought a Raspberry Pi 3 model B because I started learning Python in the University and I love the idea of making robots.

I started with the babis though: Controlling LEDs, and this came out from my mind (I used Python 3):

print('ok')
import sys
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
GPIO.output(17 , False)
GPIO.output(22 , False)
GPIO.output(27 , False)
while True:
    color = input('insert color: ')
    state = input('insert state: ')
    if color=='red':
        color=17
    if color=='yellow':
        color=22
    if color=='blue':
        color=27
    if state=='on':
        state=True
    if state=='off':
        state=False
    GPIO.output(color , state)
    print('Done!')
    if GPIO.output(17 , True) and GPIO.output(22 , True) and GPIO.output(27 , True):
        time.sleep(.5)
        GPIO.output(17 , False)
        GPIO.output(22 , False)
        GPIO.output(27 , False)
        for x in range(0,7):
            GPIO.output(27 , False)
            GPIO.output(17 , True)
            time.sleep(.5)
            GPIO.output(17 , False)
            GPIO.output(22 , True)
            time.sleep(.5)
            GPIO.output(22 , False)
            GPIO.output(27 , True)
            time.sleep(.5)

So, this program does only two easy things:

  1. Controlling LEDs
  2. Doing a good looking "light-show" after all the lights were turned on.

The first part works well. But the second one:

if GPIO.output(17 , True) and GPIO.output(22 , True) and GPIO.output(27 , True):
        time.sleep(.5)
        GPIO.output(17 , False)
        GPIO.output(22 , False)
        GPIO.output(27 , False)
        for x in range(0,7):
            GPIO.output(27 , False)
            GPIO.output(17 , True)
            time.sleep(.5)
            GPIO.output(17 , False)
            GPIO.output(22 , True)
            time.sleep(.5)
            GPIO.output(22 , False)
            GPIO.output(27 , True)
            time.sleep(.5)

just seems non-existent

So I ran a script, only without the first part and it worked!

Could you tell me why I'm having this issue?

3

The command GPIO.output(X , True) unconditionally sets GPIO X high. It does not return any meaningful status.

That means that the line

if GPIO.output(17 , True) and GPIO.output(22 , True) and GPIO.output(27 , True):

does nothing useful.

  • More specifically, I believe GPIO.output returns the special value None in Python terms, which should evaluate to false. – Brick Nov 28 '17 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.