119
Chapter 9 Potentiometer & RGBLED
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.
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...