EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #35 background imageLoading...
Page #35 background image
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

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish