// #include <stdio.h>
// #include "freertos/FreeRTOS.h"
// #include "freertos/task.h"
// // #include <stdio.h>
// #include <string.h>
// #include "esp_event_loop.h" // for usleep
// #include "neopixel.h"
// #include <esp_log.h>
// void app_main() {
// printf("Hello, Wokwi!\n");
// while (true) {
// vTaskDelay(1000 / portTICK_PERIOD_MS);
// }
// }
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "led_strip.h"
#include "sdkconfig.h"
static const char *TAG = "example";
/* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
or you can edit the following line and set a number here.
*/
// #define BLINK_GPIO CONFIG_BLINK_GPIO
static uint32_t s_led_state = 0;
#ifdef CONFIG_BLINK_LED_RMT
static uint8_t CONFIG_BLINK_PERIOD = 1000;
static uint8_t BLINK_GPIO = 8;
static led_strip_handle_t led_strip;
static void blink_led(void)
{
/* If the addressable LED is enabled */
if (s_led_state) {
/* Set the LED pixel using RGB from 0 (0%) to 255 (100%) for each color */
led_strip_set_pixel(led_strip, 0, 16, 0, 0);
/* Refresh the strip to send data */
led_strip_refresh(led_strip);
} else {
/* Set all LED off to clear all pixels */
led_strip_clear(led_strip);
}
}
// static void configure_led(void)
// {
// ESP_LOGI(TAG, "Example configured to blink addressable LED!");
// /* LED strip initialization with the GPIO and pixels number*/
// led_strip_config_t strip_config = {
// .strip_gpio_num = 8,
// .max_leds = 1, // at least one LED on board
// };
// led_strip_rmt_config_t rmt_config = {
// .resolution_hz = 10 * 1000 * 1000, // 10MHz
// };
// ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
// /* Set all LED off to clear all pixels */
// led_strip_clear(led_strip);
// }
#elif CONFIG_BLINK_LED_GPIO
static void blink_led(void)
{
/* Set the GPIO level according to the state (LOW or HIGH)*/
gpio_set_level(8, s_led_state);
}
// static void configure_led(void)
// {
// ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
// gpio_reset_pin(8);
// /* Set the GPIO as a push/pull output */
// gpio_set_direction(8, GPIO_MODE_OUTPUT);
// }
#endif
void app_main(void)
{
/* Configure the peripheral according to the LED type */
// configure_led();
ESP_LOGI(TAG, "Example configured to blink addressable LED!");
/* LED strip initialization with the GPIO and pixels number*/
led_strip_config_t strip_config = {
.strip_gpio_num = 8,
.max_leds = 1, // at least one LED on board
};
led_strip_rmt_config_t rmt_config = {
.resolution_hz = 10 * 1000 * 1000, // 10MHz
};
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
/* Set all LED off to clear all pixels */
led_strip_clear(led_strip);
while (1) {
ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
// blink_led();
/* Toggle the LED state */
s_led_state = !s_led_state;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Loading
esp32-c6-devkitc-1
esp32-c6-devkitc-1