Instructions

KY-009 RGB LED SMD module
Example program ON/OFF download
KY009_RPi_ON-OFF
To start, enter the command:
sudo python KY009_RPI_ON-OFF.py
Code example PWM
You can regulate the brightness of the LEDs via pulse-width modulation. The LEDs will be switched ON and
OFF for specific time periods, in which the relation between ON and OFF leads to a relative brightness,
because of the Inertia of the human eyesight, the human eye interprets the ON/OFF as a brightness change.
For more information to that theme visit:[ ]
Artikel von mikrokontroller.net
This module provides a few LEDs - with the overlay of the different brightness levels, you can create
different colors. This will be shown in the following code example. At the Raspberry Pi, only one Hardware-
PWM channel is carried out unrestricted to the GPIO pins, that's why we have used Software-PWM on this
example.
# Needed modules will be imported and configured.
import random, time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
<br /># Declaration of the output pins, which are connected with the LEDs.
LED_Red = 6
LED_Green = 5
LED_Blue = 4
# Set pins to output mode
GPIO.setup(LED_Red, GPIO.OUT)
GPIO.setup(LED_Green, GPIO.OUT)
GPIO.setup(LED_Blue, GPIO.OUT)
Freq = 100 #Hz
# The different colors will be initialized.
RED = GPIO.PWM(LED_Red, Freq)
GREEN = GPIO.PWM(LED_Green, Freq)
BLUE = GPIO.PWM(LED_Blue, Freq)
RED.start(0)
GREEN.start(0)
BLUE.start(0)
# This function generates the actually color
def LED_color(Red, Green, Blue, pause):
RED.ChangeDutyCycle(Red)
GREEN.ChangeDutyCycle(Green)
BLUE.ChangeDutyCycle(Blue)
time.sleep(pause)
RED.ChangeDutyCycle(0)
GREEN.ChangeDutyCycle(0)
print "LED-Test [press ctrl+c to end the test]"
# Main program loop:
# The task of this loop is to create for every single color an own variable.
# By mixing the brightness levels of the colors, you will get a color gradient.
Export: 16.06.2017 Copyright by Joy-IT - Published under CC BY-NC-SA 3.0 Page 41 of 214