Added led matrix

This commit is contained in:
Matthias Mitscherlich
2023-01-17 16:30:14 +01:00
parent 58b63fb7a2
commit 027dd38eb9
4 changed files with 328 additions and 23 deletions
+45 -23
View File
@@ -15,6 +15,7 @@
#include "inc/gpio.h"
#include "inc/led_strip_encoder.h"
#include "inc/ledmatrix.h"
#include "inc/logger.h"
#include "inc/wifi.h"
@@ -25,6 +26,10 @@ static GPIO gpio0(4, GPIO_DIRECTION_OUTPUT);
static GPIO gpio1(18, GPIO_DIRECTION_OUTPUT);
static time_t currentTime;
static rmt_channel_handle_t led_chan = NULL;
static rmt_transmit_config_t tx_config;
static rmt_encoder_handle_t led_encoder = NULL;
#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
@@ -62,14 +67,13 @@ extern "C" void app_main(void)
//
Logger logger(10, uartPort);
LOGGER_DEBUG("YEAHAAA");
LOGGER_DEBUG("Let's start the WORDCLOCK");
//--------------------------------------------
// 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));
@@ -82,7 +86,6 @@ extern "C" void app_main(void)
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;
@@ -92,13 +95,23 @@ extern "C" void app_main(void)
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;
//--------------------------------------------
// LED Matrix
//
LEDMatrix_Parameters_t ledmatrix_parameters;
ledmatrix_parameters.columOrientation = LEDMATRIX_ORIENTATION_COLUM_DOWN_UP;
ledmatrix_parameters.height = 10;
ledmatrix_parameters.matrixOrientation = LEDMATRIX_ORIENTATION_COLUM;
ledmatrix_parameters.rmtChannel = &led_chan;
ledmatrix_parameters.rmtConfig = &tx_config;
ledmatrix_parameters.rmtEncoder = &led_encoder;
ledmatrix_parameters.rowOrientation = LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT;
ledmatrix_parameters.width = 11;
LEDMatrix LEDMatrix(&ledmatrix_parameters);
// Create the development task
@@ -118,33 +131,42 @@ extern "C" void app_main(void)
sntp_init();
uint8_t led_strip_pixels[111 * 3];
int counter = 0;
unsigned int row = 0;
unsigned int colum = 0;
while (true)
{
struct tm tm;
time(&currentTime);
localtime_r(&currentTime, &tm);
// struct tm tm;
// time(&currentTime);
// localtime_r(&currentTime, &tm);
//
// LOGGER_INFO("%lld\n\r", currentTime);
// LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
//
// vTaskDelay(300);
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)
LOGGER_DEBUG("Enable pixel (%i:%i)", row, colum);
LEDMatrix.setPixelValue(row, colum, true);
vTaskDelay(100);
LEDMatrix.setPixelValue(row, colum, false);
if (row<10)
{
counter++;
row++;
}
else
{
counter = 0;
row = 0;
if(colum < 2)
{
colum++;
}
else
{
colum = 0;
}
}
rmt_transmit(led_chan, led_encoder, led_strip_pixels, sizeof(led_strip_pixels), &tx_config);
vTaskDelay(5);
}
}