SunFounder ESP32 Starter Kit
Write the RGB value into color_set(), you will be able to see the RGB light up the colors you want.
How it works?
1. Define the GPIO pins, the PWM channels and the frequency (in Hz) and resolution (in bits).
// Define RGB LED pins
const int redPin = 27;
const int greenPin = 26;
const int bluePin = 25;
// Define PWM channels
const int redChannel = 0;
const int greenChannel = 1;
const int blueChannel = 2;
// Define PWM frequency and resolution
const int freq = 5000;
const int resolution = 8;
2. The setup() function initializes the PWM channels with the specified frequency and resolution, and then at-
taches the LED pins to their corresponding PWM channels.
void setup() {
// Set up PWM channels
ledcSetup(redChannel, freq, resolution);
ledcSetup(greenChannel, freq, resolution);
ledcSetup(blueChannel, freq, resolution);
// Attach pins to corresponding PWM channels
ledcAttachPin(redPin, redChannel);
ledcAttachPin(greenPin, greenChannel);
ledcAttachPin(bluePin, blueChannel);
(continues on next page)
1.7. 2.3 Colorful Light 29