我最近开始使用两种带有一些 LED 的 ESP 板,但我真的希望使用板载板并摆脱外部 LED。
Boatds - ESP32 c3 mini 和 TTGO T1
Languegee - C++ ...(未来的微型 python)
简短阅读解释说,板载 LED 不是普通 LED,而是“可寻址”RGB LED,因此仅切换输出的示例将不起作用”,这是我能找到的唯一指南。
我怀疑我的 GPIO 引脚是从网上阅读的数字 8 但我找不到示例代码,chatGPT 完全丢失了
希望得到杏的帮助。
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 = nullptr;
// data sequence in WS2812 is GRB instead of RGB
int color[] = {0, 0, 255}; // blue
int black[] = {0, 0, 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 setup()
{
if ((rmt_send = rmtInit(BUILTIN_RGBLED_PIN, RMT_TX_MODE, RMT_MEM_64)) == nullptr)
{
Serial.println("init sender failed\n");
}
rmtSetTick(rmt_send, 100);
}
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);
}