Added LED encoder - functional
This commit is contained in:
+70
-9
@@ -5,15 +5,18 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_sntp.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "time.h"
|
||||
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "inc/gpio.h"
|
||||
#include "driver/rmt_tx.h"
|
||||
#include "driver/uart_select.h"
|
||||
#include "inc/wifi.h"
|
||||
|
||||
#include "inc/gpio.h"
|
||||
#include "inc/led_strip_encoder.h"
|
||||
#include "inc/logger.h"
|
||||
#include "inc/wifi.h"
|
||||
|
||||
static const uart_port_t uartPort = UART_NUM_0;
|
||||
static TaskHandle_t devTaskHandle = NULL;
|
||||
@@ -22,6 +25,8 @@ static GPIO gpio0(4, GPIO_DIRECTION_OUTPUT);
|
||||
static GPIO gpio1(18, GPIO_DIRECTION_OUTPUT);
|
||||
static time_t currentTime;
|
||||
|
||||
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
|
||||
#define RMT_LED_STRIP_GPIO_NUM 8
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
@@ -52,17 +57,54 @@ extern "C" void app_main(void)
|
||||
ESP_ERROR_CHECK(uart_set_pin(uartPort, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||
ESP_ERROR_CHECK(uart_driver_install(uartPort, 1024, 1024, 0, NULL, 0));
|
||||
|
||||
uart_write_bytes(uartPort, "helloWorld", sizeof("helloworld"));
|
||||
|
||||
//--------------------------------------------
|
||||
// LOGGER
|
||||
//
|
||||
Logger logger(10, uartPort);
|
||||
logger.Logger_log(__FILE__, __func__, __LINE__, LOGTYPE_DEBUG, "Hello World from the Logger himself");
|
||||
|
||||
LOGGER_DEBUG("YEAHAAA");
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
// RMT Channel
|
||||
//
|
||||
LOGGER_INFO("Create RMT TX channel");
|
||||
rmt_channel_handle_t led_chan = NULL;
|
||||
rmt_tx_channel_config_t tx_chan_config;
|
||||
memset(&tx_chan_config, 0, sizeof(tx_chan_config));
|
||||
|
||||
tx_chan_config.clk_src = RMT_CLK_SRC_DEFAULT; // select source clock
|
||||
tx_chan_config.gpio_num = RMT_LED_STRIP_GPIO_NUM;
|
||||
tx_chan_config.mem_block_symbols = 64; // increase the block size can make the LED less flickering
|
||||
tx_chan_config.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ;
|
||||
tx_chan_config.trans_queue_depth = 4;
|
||||
|
||||
ESP_ERROR_CHECK(rmt_new_tx_channel(&tx_chan_config, &led_chan));
|
||||
|
||||
LOGGER_INFO("Install led strip encoder");
|
||||
rmt_encoder_handle_t led_encoder = NULL;
|
||||
led_strip_encoder_config_t encoder_config;
|
||||
memset(&encoder_config, 0, sizeof(encoder_config));
|
||||
encoder_config.resolution = RMT_LED_STRIP_RESOLUTION_HZ;
|
||||
|
||||
ESP_ERROR_CHECK(rmt_new_led_strip_encoder(&encoder_config, &led_encoder));
|
||||
|
||||
LOGGER_INFO("Enable RMT TX channel");
|
||||
ESP_ERROR_CHECK(rmt_enable(led_chan));
|
||||
|
||||
rmt_transmit_config_t tx_config;
|
||||
memset(&tx_config, 0, sizeof(tx_config));
|
||||
tx_config.loop_count = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Create the development task
|
||||
if(xTaskCreate(devTask, "DevTask", 2048, NULL, 3, &devTaskHandle) != pdPASS)
|
||||
{
|
||||
printf("Task not created");
|
||||
LOGGER_ERROR("Task not created");
|
||||
}
|
||||
|
||||
Wifi wifi;
|
||||
@@ -75,6 +117,9 @@ extern "C" void app_main(void)
|
||||
sntp_setservername(0, "pool.ntp.org");
|
||||
sntp_init();
|
||||
|
||||
|
||||
uint8_t led_strip_pixels[111 * 3];
|
||||
int counter = 0;
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -82,9 +127,24 @@ extern "C" void app_main(void)
|
||||
time(¤tTime);
|
||||
localtime_r(¤tTime, &tm);
|
||||
|
||||
printf("%lld\n\r", currentTime);
|
||||
printf("%i:%i:%i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
vTaskDelay(1000);
|
||||
LOGGER_INFO("%lld\n\r", currentTime);
|
||||
LOGGER_INFO("%i:%i:%i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
|
||||
memset(&led_strip_pixels, 0, sizeof(led_strip_pixels));
|
||||
led_strip_pixels[counter * 3 + 0] = 0x3F;
|
||||
led_strip_pixels[counter * 3 + 1] = 0x3F;
|
||||
led_strip_pixels[counter * 3 + 2] = 0x3F;
|
||||
|
||||
if (counter < 111)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
}
|
||||
rmt_transmit(led_chan, led_encoder, led_strip_pixels, sizeof(led_strip_pixels), &tx_config);
|
||||
vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +160,7 @@ static void devTask(void* parameters)
|
||||
(void)gpio0.SetOutput((GPIO_Value_t)(counter % 2));
|
||||
(void)gpio1.SetOutput((GPIO_Value_t)(counter % 7));
|
||||
counter++;
|
||||
|
||||
vTaskDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user