EasyManua.ls Logo

Freenove Ultimate Starter Kit - Page 119

Freenove Ultimate Starter Kit
286 pages
Print Icon
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...
119
Chapter 9 Potentiometer & RGBLED
ā–ˆ www.freenove.com
support@freenove.com ā–ˆ
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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.

Table of Contents