EasyManua.ls Logo

Freenove Ultimate Starter Kit - Page 121

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
Loading...
121
Chapter 9 Potentiometer & RGBLED
ā–ˆ www.freenove.com
support@freenove.com ā–ˆ
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def loop():
w hile Tr ue:
value_Red = analogRead(0) #read ADC value of 3 potentiometers
value_Green = analogRead(1)
value_Blue = analogRead(2)
p_Red.ChangeDutyCycle(value_Red*100/255) #map the read value of potentiometers
into PWM value and output it
p_Green.ChangeDutyCycle(value_Green*100/255)
p_Blue.ChangeDutyCycle(value_Blue*100/255)
#print read ADC value
print ('ADC Value
value_Red: %d ,\tvlue_Green: %d ,\tvalue_Blue: %d'%(value_Red,value_Green,value_Blue))
time.sleep(0.01)
def destroy():
bus. close()
GPIO. cleanup()
if __name__ == '__main__':
p rint 'Program is starting ... '
setup()
try:
loop()
e xcept KeyboardInterrupt:
destroy()
In the code, read the ADC value of 3 potentiometers and map it into PWM duty cycle to control the control
3 LEDs with different color of RGBLED, respectively.

Table of Contents