User Manual
55
Step 1: Build the circuit
For C language users:
Step 2: Open the code file
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C
Step 3: Compile the Code
make 05_rgb
Step 4: Run the executable file above
sudo ./05_rgb
Code Explanation
#include <softPwm.h> // library used for realizing the pwm function of the software.
void ledInit(void){ // define function used for initializing I/O port to output for
pwm.
// LedPinX refers to one pin. 0 is the minimum value and 100 is the maximum (as a
percentage). The function is to use software to create a PWM pin, set its value between
0-100%.
softPwmCreate(LedPinRed, 0, 100);
softPwmCreate(LedPinGreen,0, 100);
softPwmCreate(LedPinBlue, 0, 100);
void ledColorSet(uchar r_val, uchar g_val, uchar b_val){ // This function is to set the
colors of the LED. Using RGB, the formal parameter r_val represents the luminance of the
red one, g_val of the green one, b_val of the blue one. The three formal parameters’
different values corresponds to various colors. You can modify the 3 formal parameters
randomly to verify.
softPwmWrite(LedPinRed, r_val);
softPwmWrite(LedPinGreen, g_val);
SunFounder