EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #86 background imageLoading...
Page #86 background image
Chapter 5 RGBLED
86
www.freenove.com
support@freenove.com
The related function of Software PWM can be described as follws:
int softPwmCreate (int pin, int initialValue, int pwmRange) ;
This creates a software controlled PWM pin.
void softPwmWrite (int pin, int value) ;
This updates the PWM value on the given pin.
long random();
This function will return a random number.
For more details about Software PWM, please refer to: http://wiringpi.com/reference/software-pwm-library/
Python Code 5.1.1 ColorfulLED
First observe the project result, and then analyze the code.
1. Use cd command to enter 05.1.1_ColorfulLED directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/05.1.1_ColorfulLED
2. Use python command to execute python code “ColorfulLED.py.
python ColorfulLED.py
After the program is executed, you will see that the RGBLED shows light of different color randomly.
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
im port RPi. GPIO as GPIO
im port time
im port random
pins = {'pin_R':11, 'pin_G':12, 'pin_B':13} # pins is a dict
def setup():
g lobal p_R,p_G,p_B
p rint ('Program is starting ... ')
GPIO. setmode(GPIO.BOARD) # Numbers GPIOs by physical location
for i in pins:
GPIO.setup(pins[i], GPIO. OUT) # Set pins' mode is output
GPIO.output(pins[i], GPIO. HIGH) # Set pins to high(+3.3V) to off led
p_R = GPIO.PWM(pins['pin_R'], 2000) # set Frequece to 2KHz
p_G = GPIO.PWM(pins['pin_G'], 2000)
p_B = GPIO.PWM(pins['pin_B'], 2000)
p_R. start(0) # Initial duty Cycle = 0
p_G. start(0)
p_B. start(0)
def setColor(r_val,g_val,b_val):
p_R. ChangeDutyCycle(r_val) # Change duty cycle
p_G. ChangeDutyCycle(g_val)
p_B. ChangeDutyCycle(b_val)
def loop():

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish