forked from CalinRadoni/esp32_digitalLEDs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
67 lines (53 loc) · 1.5 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_log.h"
#include "esp32_rmt_dled.h"
static const char *TAG = "main";
void delay_ms(uint32_t ms)
{
if (ms == 0) return;
vTaskDelay(ms / portTICK_PERIOD_MS);
}
void app_main(void)
{
esp_err_t err;
rmt_pixel_strip_t rps;
pixel_strip_t strip;
nvs_flash_init();
dled_strip_init(&strip);
dled_strip_create(&strip, DLED_WS281x, 300, 32);
rmt_dled_init(&rps);
err = rmt_dled_create(&rps, &strip);
if (err != ESP_OK) {
ESP_LOGE(TAG, "[0x%x] rmt_dled_init failed", err);
while(true) { }
}
err = rmt_dled_config(&rps, 16, 0);
if (err != ESP_OK) {
ESP_LOGE(TAG, "[0x%x] rmt_dled_config failed", err);
while(true) { }
}
err = rmt_dled_send(&rps);
if (err != ESP_OK) { ESP_LOGE(TAG, "[0x%x] rmt_dled_send failed", err); }
else { ESP_LOGI(TAG, "LEDs initialized and turned off"); }
uint16_t step;
step = 0;
while (step < 6 * strip.length) {
dled_pixel_move_pixel(strip.pixels, strip.length, strip.max_cc_val, step);
dled_strip_fill_buffer(&strip);
rmt_dled_send(&rps);
step++;
delay_ms(20);
}
step = 0;
while (true) {
dled_pixel_rainbow_step(strip.pixels, strip.length, strip.max_cc_val, step);
dled_strip_fill_buffer(&strip);
rmt_dled_send(&rps);
step++;
delay_ms(50);
}
vTaskDelete(NULL);
}