'Writing a super simple LED code, having issues with not being able to import from gpiozero
Im trying to use my raspberry pi electronics kit to run an LED program. My code is just:
from gpiozero import led
from signal import pause
led = LED(4)
led.blink()
pause()
Which throws
Traceback (most recent call last):
File "/home/pi/python-projects/led.py", line 1, in <module>
from gpiozero import led
ImportError: cannot import name 'led' from 'gpiozero' (/usr/lib/python3/dist-packages/gpiozero/__init__.py)
>>>
I have tried reinstalling throught apt with sudo apt-get update && sudo apt-get install python3-gpiozero python-gpiozero but nothing has changed. Im sure its something stupidly simple, I just dont know enough yet to figure it out
Solution 1:[1]
As per the documentation, it should be LED, not led:
from gpiozero import LED
from time import sleep
led = LED(17)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roland Smith |
