I am using the gpiozero library to controll a LED strip and a relay connected to my raspberry pi 4. This is the way I connected the LED strip to the pins. I use a type SMD5050 LED strip similar to the one in this blog post (you can chose English in the top right corner). Below is the code that controlls my LED, from which I call toggle_led() in a small Flask app (python3).
Now when I call the command the LED strip changes color, so that's good. But for some reason the color fades after 7-8 seconds back to white light without any further interaction. Also, I can only toggle one color at a time. If I switch on red and then green, red is switched off instead of switching both on... I use these MOSFETs, is that maybe the wrong type? I'm fairly new to this, sorry.
What i want to achieve: Switch more than one color on/off at the same time ("mixing" them) and have them stay on until I send another command. Thanks for your help.
from gpiozero import LED def toggle_led(color, pinr=6, ping=26, pinb=16): #print(color) red = LED(pinr) green = LED(ping) blue = LED(pinb) if color == 'red': red.toggle() elif color == 'green': green.toggle() elif color == 'blue': blue.toggle() elif color == 'off': blue.off() red.off() green.off() if __name__ == "__main__": toggle_led('off')
My system info:
➜ ~ uname -a Linux raspberrypi 5.4.79-v7l+ #1373 SMP Mon Nov 23 13:27:40 GMT 2020 armv7l GNU/Linux ➜ ~ cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"