1

When I run this python script led.py it works.

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(24,GPIO.OUT)
print("LED on")
GPIO.output(24,GPIO.HIGH)
time.sleep(1)
print("LED off")
GPIO.output(24,GPIO.LOW)

but if I open python3 shell and paste the above code

script# python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> import time
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setwarnings(False)
>>> GPIO.setup(24,GPIO.OUT)
>>> print("LED on")
LED on

then it does not work. what is happening here

Ciasto piekarz
  • 355
  • 2
  • 12
  • 28

1 Answers1

1

You are not setting the GPIO level.

The LED will go on when you execute

GPIO.output(24,GPIO.HIGH)

The LED will go off when you execute

GPIO.output(24,GPIO.LOW)
joan
  • 71,852
  • 5
  • 76
  • 108