// Franzininho WiFi ESP-IDF Multitasking Example
#include <stdio.h>
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define LED_RED GPIO_NUM_17
#define LED_GREEN GPIO_NUM_16
#define LED_BLUE GPIO_NUM_15
struct led_task_parameters_t {
gpio_num_t led_gpio;
TickType_t blink_time;
};
static led_task_parameters_t red_led_gpio = {LED_RED, 2000};
static led_task_parameters_t green_led_gpio = {LED_GREEN, 1000};
static led_task_parameters_t blue_led_gpio = {LED_BLUE, 500};
void led_task(void *pvParameter)
{
uint8_t led_value = 0;
gpio_num_t led_gpio = ((led_task_parameters_t *)pvParameter)->led_gpio;
TickType_t blink_time = ((led_task_parameters_t *)pvParameter)->blink_time;
gpio_reset_pin(led_gpio);
gpio_set_direction(led_gpio, GPIO_MODE_OUTPUT);
while (1) {
gpio_set_level(led_gpio, led_value);
led_value = !led_value;
vTaskDelay(blink_time / portTICK_PERIOD_MS);
}
vTaskDelete(NULL);
}
extern "C" void app_main()
{
xTaskCreate(
&led_task, // Task function
"red_led_task", // Task name
2048, // Stack size in words
&red_led_gpio, // Pointer to parameters
5, // Priority
NULL); // Out pointer to task handle
xTaskCreate(
&led_task, // Task function
"green_led_task", // Task name
2048, // Stack size in words
&green_led_gpio, // Pointer to parameters
5, // Priority
NULL); // Out pointer to task handle
xTaskCreate(
&led_task, // Task function
"blue_led_task", // Task name
2048, // stack size in words
&blue_led_gpio, // Pointer to parameters
5, // Priority
NULL); // Out pointer to task handle
}
esp:0
esp:1
esp:2
esp:3
esp:4
esp:5
esp:6
esp:7
esp:8
esp:9
esp:10
esp:11
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:21
esp:26
esp:33
esp:34
esp:35
esp:36
esp:37
esp:38
esp:39
esp:40
esp:41
esp:42
esp:43
esp:44
esp:45
esp:46
esp:3V3.1
esp:GND.1
esp:3V3.2
esp:GND.7
esp:SDA
esp:SCL
esp:5V.1
esp:GND.3
esp:GND.2
esp:5V.2
esp:GND.4
esp:GND.5
esp:GND.6
esp:5V.3
esp:21.2
led-red:A
led-red:C
led-green:A
led-green:C
led-blue:A
led-blue:C
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2