This repository contains Arduino code for controlling the built-in RGB LED on the ESP32-C6 microcontroller. It provides a simple and flexible way to manage LED colors.
The built-in RGB LED on the ESP32-C6 is connected to GPIO 8
. This is already configured in the code, but it’s crucial to know if you’re working with other components or modifying the pin configuration.
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
…
LED_PIN
is set to 8
for the built-in LED. Do not change this unless you’re using an external LED.RGB
struct formatsetColor()
function with different delaysBLINK_DURATION
to change the speed of the blinking pattern…
esp32_c6_rgb_led_control.ino
file.ino
file in Arduino IDEHere’s the basic code structure:
#include <Adafruit_NeoPixel.h>
constexpr uint8_t LED_PIN = 8;
constexpr uint8_t NUM_LEDS = 1;
Adafruit_NeoPixel rgbLed(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
struct RGB {
uint8_t r, g, b;
};
constexpr RGB COLOR_OFF = {0, 0, 0};
// ...Feel free to add more colors here...
constexpr RGB CUSTOM_COLOR = {255, 0, 255};
void setup() {
rgbLed.begin();
rgbLed.show();
}
void setColor(const RGB& color) {
rgbLed.setPixelColor(0, rgbLed.Color(color.r, color.g, color.b));
rgbLed.show();
}
void loop() {
setColor(CUSTOM_COLOR);
delay(500);
setColor(COLOR_OFF);
delay(500);
}
Contributions to improve the code or add new features are welcome. Please feel free to submit a pull request or open an issue.