This library provides basic functionality to control single LEDs and RGB LEDs using the LEDC peripheral on the ESP-IDF framework. It includes functions for setting up LEDs, RGB LEDs, and controlling their brightness and color through PWM channels.
- Setup individual LEDs and RGB LEDs on specified GPIO pins.
- Control the brightness of single LEDs.
- Set the color and brightness of RGB LEDs using 24-bit RGB values.
- Uses the ESP-IDF's LEDC peripheral for PWM control.
-
Setup LEDC Peripheral
- Initializes the LEDC timer for PWM signal generation.
esp_err_t setupLEDC(void);
-
Setup RGB LED
- Configures an RGB LED with separate channels for Red, Green, and Blue.
esp_err_t setupRGBLED(rgb_led_t *led);
-
Setup Single LED
- Configures a single LED channel.
esp_err_t setupLED(led_t *led);
-
Set RGB LED Color and Brightness
- Set the color and brightness of an RGB LED. Colors are represented as a 24-bit value (0xRRGGBB).
esp_err_t setRGBLED(rgb_led_t *led, uint32_t color, uint8_t brightness);
-
Set LED Brightness
- Adjusts the brightness of a single LED.
esp_err_t setLED(led_t *led, uint8_t brightness);
// Define an RGB LED on specific pins
rgb_led_t rgbLed = {
.red_channel = LEDC_CHANNEL_0,
.red_pin = 4,
.green_channel = LEDC_CHANNEL_1,
.green_pin = 5,
.blue_channel = LEDC_CHANNEL_2,
.blue_pin = 6
};
// Setup the LEDC and RGB LED
setupLEDC();
setupRGBLED(&rgbLed);
// Set the RGB LED to blue at half brightness
setRGBLED(&rgbLed, 0x0000FF, 128);
- Switch GPIO pin configuration from
int
togpio_num_t
for better type safety. - Add LED naming for improved identification in multi-LED setups.
Apache License 2.0