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 #120 background imageLoading...
Page #120 background image
Chapter 9 Potentiometer & RGBLED
120
www.freenove.com
support@freenove.com
Python Code 9.1.1 ColorfulSoftlight
First observe the project result, and then analyze the code.
1. Use cd command to enter 09.1.1_ColorfulSoftlight directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/09.1.1_ ColorfulSoftlight
2. Use python command to execute python code "ColorfulSoftlight.py".
python ColorfulSoftlight.py
After the program is executed, rotate one of potentiometers, then the color of RGBLED will change
consequently. And the terminal window will print out the ADC value of each potentiometer.
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
27
28
29
30
31
32
33
34
35
im port RPi. GPIO as GPIO
im port smbus
im port time
address = 0x48
bus=smbus.SMBus(1)
cmd=0x40
ledRedPin = 15 #define 3 pins of RGBLED
ledGreenPin = 13
ledBluePin = 11
def analogRead(chn): #read ADC value
bus. write_byte(address,cmd+chn)
value = bus.read_byte(address)
value = bus. read_byte(address) #This function always return the last data read.
#If you want return the current data, you need execute it twice.
r eturn value
def analogWrite(value):
bus. write_byte_data(address,cmd,value)
def setup():
g lobal p_Red,p_Green,p_Blue
GPIO. setmode(GPIO.BOARD)
GPIO. setup(ledRedPin,GPIO.OUT) #set 3 pins of RGBLED to output mode
GPIO. setup(ledGreenPin,GPIO.OUT)
GPIO. setup(ledBluePin,GPIO.OUT)
p_Red = GPIO.PWM(ledRedPin,1000) #configure PWM to 3 pins of RGBLED
p_Red. start(0)
p_Green = GPIO. PWM(ledGreenPin,1000)
p_Green.start(0)
p_Blue = GPIO.PWM(ledBluePin,1000)
p_Blue.start(0)

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