How to do it...

  1. Create the ledtest.py script as follows:
#!/usr/bin/python3 #ledtest.py import time import RPi.GPIO as GPIO # RGB LED module #HARDWARE SETUP # GPIO # 2[======XRG=B==]26[=======]40 # 1[=============]25[=======]39 # X=GND R=Red G=Green B=Blue #Setup Active States #Common Cathode RGB-LED (Cathode=Active Low) RGB_ENABLE = 1; RGB_DISABLE = 0 #LED CONFIG - Set GPIO Ports RGB_RED = 16; RGB_GREEN = 18; RGB_BLUE = 22 RGB = [RGB_RED,RGB_GREEN,RGB_BLUE] def led_setup(): #Setup the wiring GPIO.setmode(GPIO.BOARD) #Setup Ports for val in RGB: GPIO.setup(val,GPIO.OUT) def main(): led_setup() for val in RGB: GPIO.output(val,RGB_ENABLE) print("LED ON") time.sleep(5) GPIO.output(val,RGB_DISABLE) print("LED OFF") try: main() finally: GPIO.cleanup() ...

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.