softPwmCreate(ledBluePin,0,100);
pcf8591Setup(pinbase,address); //initialize PCF8591
while(1){
val_Red = analogRead(A0); //read 3 potentiometers
val_Green = analogRead(A1);
val_Blue = analogRead(A2);
softPwmWrite(ledRedPin,val_Red*100/255); //map the read value of
potentiometers into PWM value and output it
softPwmWrite(ledGreenPin,val_Green*100/255);
softPwmWrite(ledBluePin,val_Blue*100/255);
//print out the read ADC value
printf("ADC value val_Red: %d ,\tval_Green: %d ,\tval_Blue: %d
\n",val_Red,val_Green,val_Blue);
delay(100);
}
return 0;
}
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.