如何让 ESP 板载 LED 闪烁?

问题描述 投票:0回答:1

最近我开始使用两种带有一些 LED 指示灯的 ESP 板,但我真的希望使用板载板并摆脱外部 LED。请帮忙

Boatds - ESP32 c3 mini 和 TTGO T1 Languegee - C++ ...(未来的微型 python)

简短的阅读说明告诉我,这样的 LED 不是普通的引脚,而是“它是一个“可寻址”RGB LED,因此仅切换输出的示例将无法工作”,这是我能找到的唯一指南。

我怀疑我的 GPIO 引脚是从网上阅读的数字 8 但我找不到示例代码,chatGPT 完全丢失了

希望得到杏石的帮助

c++ arduino iot esp32
1个回答
0
投票

ESP32 有一个用于寻址 8x4 LED 条的示例代码,称为 RMTWriteNeoPixel,当板上有一个 NeoPixel 时,它看起来像闪烁。

我修改了自己定制的 ESP32-C3 板的代码作为基本的眨眼草图。


#define BUILTIN_RGBLED_PIN   8

#define NR_OF_LEDS   1
#define NR_OF_ALL_BITS 24*NR_OF_LEDS

rmt_data_t led_data[NR_OF_ALL_BITS];

rmt_obj_t* rmt_send = NULL;

void setup() 
{
    
    if ((rmt_send = rmtInit(BUILTIN_RGBLED_PIN, RMT_TX_MODE, RMT_MEM_64)) == NULL)
    {
        Serial.println("init sender failed\n");
    }

    rmtSetTick(rmt_send, 100);

}

// data sequence in WS2812 is GRB instead of RGB
int color[] = {0, 0, 255};  // blue
int black[] = {0, 0, 0};

int led_index = 0;

void setColor(rmt_data_t * l_data, int * color) {
    int i=0;
    for (int col=0; col<3; col++ ) {
        for (int b=0; b<8; b++){
            if ( color[col] & (1<<(7-b)) ) {
                l_data[i].level0 = 1;
                l_data[i].duration0 = 8;
                l_data[i].level1 = 0;
                l_data[i].duration1 = 4;
            } else {
                l_data[i].level0 = 1;
                l_data[i].duration0 = 4;
                l_data[i].level1 = 0;
                l_data[i].duration1 = 8;
            }
            i++;
        }
    }
}

void loop() 
{
  // set NeoPixel to the defined color
  setColor(led_data, color);
  rmtWrite(rmt_send, led_data, NR_OF_ALL_BITS);
  vTaskDelay(500/portTICK_PERIOD_MS);

  // set NeoPixel to Black
  setColor(led_data, black);
  rmtWrite(rmt_send, led_data, NR_OF_ALL_BITS);
  vTaskDelay(500/portTICK_PERIOD_MS);
    
}
© www.soinside.com 2019 - 2024. All rights reserved.