mirror of
https://github.com/espressif/arduino-esp32
synced 2024-09-21 18:38:17 +00:00
05ae83a051
* Improve RGB LED Driver Replaces the use of the `LED_BUILTIN` variable by creating a new variable called `RGB_BUILTIN`. On boards with both a regular LED and RGB LED, this change provides functionality to control either LED. The `LED_BRIGHTNESS` variable is changed to `RGB_BRIGHTNESS`, which aligns more closely with the `RGB_BUILTIN` variable name. `BOARD_HAS_NEOPIXEL` is no longer necessary; it is replaced by `RGB_BUILTIN`. * Update BlinkRGB example Update example code for changes with the RGB driver: - Replace `LED_BUILTIN` and `BOARD_HAS_NEOPIXEL` with `RGB_BUILTIN` - Replace `LED_BRIGHTNESS` with `RGB_BRIGHTNESS` * Update board variants Update board variants for changes with the RGB driver: - Remove `BOARD_HAS_NEOPIXEL` - Define `RGB_BUILTIN` pin - Replace `LED_BRIGHTNESS` with `RGB_BRIGHTNESS` to align with `RGB_BUILTIN` name Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com> Co-authored-by: Vojtěch Bartoška <76958047+VojtechBartoska@users.noreply.github.com>
48 lines
1.2 KiB
C
48 lines
1.2 KiB
C
#include "esp32-hal-rgb-led.h"
|
|
|
|
|
|
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){
|
|
rmt_data_t led_data[24];
|
|
static rmt_obj_t* rmt_send = NULL;
|
|
static bool initialized = false;
|
|
|
|
uint8_t _pin = pin;
|
|
#ifdef RGB_BUILTIN
|
|
if(pin == RGB_BUILTIN){
|
|
_pin = RGB_BUILTIN-SOC_GPIO_PIN_COUNT;
|
|
}
|
|
#endif
|
|
|
|
if(!initialized){
|
|
if((rmt_send = rmtInit(_pin, RMT_TX_MODE, RMT_MEM_64)) == NULL){
|
|
log_e("RGB LED driver initialization failed!");
|
|
rmt_send = NULL;
|
|
return;
|
|
}
|
|
rmtSetTick(rmt_send, 100);
|
|
initialized = true;
|
|
}
|
|
|
|
int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE
|
|
int i = 0;
|
|
for(int col=0; col<3; col++ ){
|
|
for(int bit=0; bit<8; bit++){
|
|
if((color[col] & (1<<(7-bit)))){
|
|
// HIGH bit
|
|
led_data[i].level0 = 1; // T1H
|
|
led_data[i].duration0 = 8; // 0.8us
|
|
led_data[i].level1 = 0; // T1L
|
|
led_data[i].duration1 = 4; // 0.4us
|
|
}else{
|
|
// LOW bit
|
|
led_data[i].level0 = 1; // T0H
|
|
led_data[i].duration0 = 4; // 0.4us
|
|
led_data[i].level1 = 0; // T0L
|
|
led_data[i].duration1 = 8; // 0.8us
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
rmtWrite(rmt_send, led_data, 24);
|
|
}
|