I have a simple circuit connected to my Raspberry Pi 4 with 3 push buttons and an LED. The buttons are connected to gpio2(pin 3), gpio17(pin 11), and gpio16(pin36), with the LED connected to gpio25(pin 22), all grounded through gnd(pin 6). When using a simple assignment with a button and LED the LED will turn completely off with LED.off(), but when I attempted to write its' functionality into a function the LED will remain on dimly lit.
Code for a single button with simple assignments, taken from the gpiozero library documentation:
from gpiozero import LED, Button from signal import pause led = LED(25) button = Button(2) button.when_pressed = led.on button.when_released = led.off pause()
Code for lighting LED in a function, using 3 buttons for testing:
from gpiozero import LED, Button from signal import pause from time import sleep def blink_led(): led = LED(25) led.on() sleep(0.5) led.off() button1 = Button(2) button2 = Button(17) button3 = Button(16) button1.when_pressed = blink_led button2.when_pressed = blink_led button3.when_pressed = blink_led pause()
After any of the three buttons is pushed in the second code, the LED will turn on for the correct time interval, then it will "turn off" but still be dimly lit. I have to run a seperate small bit of code to turn it completely off:
from gpiozero import LED led = LED(25) led.off()
What is the reasoning behind the led still being dimly lit?
Note: there is a 330 Ohm resistor between the LED and gnd. gpiozero docs recommended a 220 Ohm but this is what I had. LED has a current rating of 20mA.
Edit: code is written in python 3.7.