LED.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/gpio.h"
  5. #include "esp_log.h"
  6. #include "led_strip.h"
  7. #include "sdkconfig.h"
  8. static const char *TAG = "LED_Control";
  9. led_strip_handle_t configure_led(void)
  10. {
  11. led_strip_config_t strip_config = {
  12. .strip_gpio_num = 38,
  13. .max_leds = 1,
  14. };
  15. // LED strip backend configuration: RMT
  16. led_strip_rmt_config_t rmt_config = {
  17. .clk_src = RMT_CLK_SRC_DEFAULT,
  18. .resolution_hz = (10 * 1000 * 1000),
  19. };
  20. led_strip_handle_t led_strip;
  21. ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
  22. ESP_LOGI(TAG, "Created LED strip object with RMT backend");
  23. return led_strip;
  24. }
  25. void LED_init(void)
  26. {
  27. led_strip_handle_t led_strip = configure_led();
  28. bool led_on_off = false;
  29. ESP_LOGI(TAG, "Start blinking LED strip");
  30. while (1) {
  31. if (led_on_off) {
  32. ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, 0, 5, 5, 5));
  33. ESP_ERROR_CHECK(led_strip_refresh(led_strip));
  34. ESP_LOGI(TAG, "LED ON!");
  35. } else {
  36. ESP_ERROR_CHECK(led_strip_clear(led_strip));
  37. ESP_LOGI(TAG, "LED OFF!");
  38. }
  39. led_on_off = !led_on_off;
  40. vTaskDelay(pdMS_TO_TICKS(500));
  41. }
  42. }