|
1 | 1 | #include "esp32-hal-gpio.h"
|
2 | 2 | #include "pins_arduino.h"
|
3 | | -#include "driver/rmt_tx.h" |
4 | 3 |
|
5 | 4 | extern "C" {
|
6 | 5 |
|
7 | | -void blinkLED(uint8_t color[3], rmt_channel_handle_t led_chan, rmt_encoder_handle_t ws2812_encoder, rmt_transmit_config_t tx_config) { |
8 | | - ESP_ERROR_CHECK(rmt_transmit(led_chan, ws2812_encoder, color, sizeof(color), &tx_config)); |
9 | | - rmt_tx_wait_all_done(led_chan, portMAX_DELAY); |
10 | | - |
11 | | - // Wait a moment |
12 | | - delay(50); |
13 | | - |
14 | | - // Turn LED off |
15 | | - uint8_t pixel_off[3] = { 0x00, 0x00, 0x00 }; |
16 | | - ESP_ERROR_CHECK(rmt_transmit(led_chan, ws2812_encoder, pixel_off, sizeof(pixel_off), &tx_config)); |
17 | | - rmt_tx_wait_all_done(led_chan, portMAX_DELAY); |
18 | | -} |
19 | | - |
20 | 6 | void initVariant(void) {
|
21 | | - rmt_channel_handle_t led_chan = NULL; |
22 | | - rmt_tx_channel_config_t tx_chan_config = {}; |
23 | | - tx_chan_config.clk_src = RMT_CLK_SRC_DEFAULT; |
24 | | - tx_chan_config.resolution_hz = 10 * 1000 * 1000; |
25 | | - tx_chan_config.mem_block_symbols = 64; |
26 | | - tx_chan_config.trans_queue_depth = 4; |
27 | | - tx_chan_config.gpio_num = (gpio_num_t)PIN_LED; |
28 | | - tx_chan_config.flags.invert_out = false; |
29 | | - tx_chan_config.flags.with_dma = false; |
30 | | - ESP_ERROR_CHECK(rmt_new_tx_channel(&tx_chan_config, &led_chan)); |
31 | | - |
32 | | - // WS2812 encoder config (available in `esp-rmt`) |
33 | | - rmt_encoder_handle_t ws2812_encoder = NULL; |
34 | | - rmt_bytes_encoder_config_t bytes_encoder_config = { |
35 | | - .bit0 = { .duration0 = 4, .level0 = 1, .duration1 = 9, .level1 = 0 }, |
36 | | - .bit1 = { .duration0 = 8, .level0 = 1, .duration1 = 5, .level1 = 0 }, |
37 | | - .flags = { .msb_first = true } |
38 | | - }; |
39 | | - ESP_ERROR_CHECK(rmt_new_bytes_encoder(&bytes_encoder_config, &ws2812_encoder)); |
40 | | - |
41 | | - ESP_ERROR_CHECK(rmt_enable(led_chan)); |
42 | | - |
43 | | - rmt_transmit_config_t tx_config = { |
44 | | - .loop_count = 0 |
45 | | - }; |
46 | | - |
47 | | - uint8_t pixel[3] = { 0x10, 0x00, 0x00 }; // green |
48 | | - blinkLED(pixel, led_chan, ws2812_encoder, tx_config); |
| 7 | + // blink the RGB LED |
| 8 | + rgbLedWrite(PIN_LED, 0x00, 0x10, 0x00); // green |
| 9 | + delay(20); |
| 10 | + rgbLedWrite(PIN_LED, 0x00, 0x00, 0x00); // off |
49 | 11 | }
|
50 | 12 | }
|
0 commit comments