How to do it...

Create the rgbled.py script and perform the following steps:

  1. Import all the required modules and define the values to be used with the help of the following code:
#!/usr/bin/python3 #rgbled.py import time import RPi.GPIO as GPIO #Setup Active states #Common Cathode RGB-LEDs (Cathode=Active Low) LED_ENABLE = 0; LED_DISABLE = 1 RGB_ENABLE = 1; RGB_DISABLE = 0 #HARDWARE SETUP # GPIO # 2[=====1=23=4==]26[=======]40 # 1[===5=RGB=====]25[=======]39 #LED CONFIG - Set GPIO Ports LED1 = 12; LED2 = 16; LED3 = 18; LED4 = 22; LED5 = 7 LED = [LED1,LED2,LED3,LED4,LED5] RGB_RED = 11; RGB_GREEN = 13; RGB_BLUE = 15 RGB = [RGB_RED,RGB_GREEN,RGB_BLUE] #Mixed Colors RGB_CYAN = [RGB_GREEN,RGB_BLUE] RGB_MAGENTA = [RGB_RED,RGB_BLUE] RGB_YELLOW ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.