/* * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "driver/gpio.h" #include "ws2812.h" #define RMT_LED_STRIP_GPIO_NUM GPIO_NUM_10 #define EXAMPLE_LED_NUMBERS 119 #define EXAMPLE_CHASE_SPEED_MS 1000 static const char *TAG = "example"; extern "C" void app_main(void) { ESP_LOGI(TAG, "Create LED strip"); WS2812 strip(RMT_LED_STRIP_GPIO_NUM, EXAMPLE_LED_NUMBERS); ESP_LOGI(TAG, "Start LED rainbow chase"); uint16_t start_rgb = 0; strip.setBrightness(16); while (true) { for (size_t i = 0; i < 3; i++) { for (size_t j = i; j < strip.size(); j += 3) { // Build RGB pixels uint32_t hue = (j * 360 / strip.size() + start_rgb) % 360; uint32_t red = 0, green = 0, blue = 0; WS2812::hsv2rgb(hue, 100, 100, &red, &green, &blue); strip.set(j, red, green, blue); } // Flush RGB values to LEDs ESP_ERROR_CHECK(strip.write()); vTaskDelay(pdMS_TO_TICKS(EXAMPLE_CHASE_SPEED_MS)); } start_rgb += 60; } }