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.