smart-home/ziyuan/led_test.cpp
2026-02-26 09:16:34 +08:00

68 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// LED引脚测试程序
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#define TAG "LED_TEST"
// 测试所有可能的LED引脚
gpio_num_t test_pins[] = {
GPIO_NUM_35, // LED1候选
GPIO_NUM_34, // LED2候选
GPIO_NUM_33, // LED3候选
GPIO_NUM_32, // LED_GREEN候选
GPIO_NUM_31, // LED4候选
GPIO_NUM_42, // 另一个候选
GPIO_NUM_41, // 另一个候选
GPIO_NUM_40, // 另一个候选
GPIO_NUM_38 // 另一个候选
};
const char* pin_names[] = {
"GPIO35(LED1)",
"GPIO34(LED2)",
"GPIO33(LED3)",
"GPIO32(LED_GREEN)",
"GPIO31(LED4)",
"GPIO42",
"GPIO41",
"GPIO40",
"GPIO38"
};
void led_test_task(void* param) {
// 初始化所有测试引脚
for (int i = 0; i < 9; i++) {
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL << test_pins[i]);
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_config(&io_conf);
gpio_set_level(test_pins[i], 0); // 初始关闭
}
ESP_LOGI(TAG, "开始LED引脚测试...");
while (true) {
// 依次点亮每个引脚持续2秒
for (int i = 0; i < 9; i++) {
ESP_LOGI(TAG, "点亮 %s", pin_names[i]);
gpio_set_level(test_pins[i], 1);
vTaskDelay(pdMS_TO_TICKS(2000)); // 2秒
gpio_set_level(test_pins[i], 0);
vTaskDelay(pdMS_TO_TICKS(500)); // 0.5秒间隔
}
ESP_LOGI(TAG, "测试循环完成等待5秒后重复...");
vTaskDelay(pdMS_TO_TICKS(5000));
}
}
extern "C" void app_main() {
ESP_LOGI(TAG, "LED引脚测试程序启动");
xTaskCreate(led_test_task, "led_test", 4096, NULL, 5, NULL);
}