#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED1_PIN 22
#define LED2_PIN 4
#define LED3_PIN 2
#define LED4_PIN 5
#define LED5_PIN 18
#define LED6_PIN 19
#define LED7_PIN 21
#define LED8_PIN 32
String data;
int K1;
int K2;
int K3;
int K4;
int K5;
int K6;
int K7;
int K8;
void task1(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K1>0){
digitalWrite(LED1_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED1_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K1 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task2(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K2>0){
digitalWrite(LED2_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED2_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K2 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task3(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K3>0){
digitalWrite(LED3_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED3_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K3 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task4(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K4>0){
digitalWrite(LED4_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED4_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K4 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task5(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K5>0){
digitalWrite(LED5_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED5_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K5 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task6(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K6>0){
digitalWrite(LED6_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED6_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K6 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task7(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K7>0){
digitalWrite(LED7_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED7_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K7 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task8(void *pvParameters) {
(void)pvParameters;
for (;;) {
if(K8>0){
digitalWrite(LED8_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
digitalWrite(LED8_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(300)); // Delay for 1 second
K8 -= 1;
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void task9(void *pvParameters) {
(void)pvParameters;
for (;;) {
vTaskDelay(pdMS_TO_TICKS(20));
data=Serial.readStringUntil('\n');
if (data == "1"){
K1 += 1;
}
else if(data == "2"){
K2 += 1;
}
else if(data == "3"){
K3 += 1;
}
else if (data == "4"){
K4 += 1;
}
else if (data == "5"){
K5 += 1;
}
else if (data == "6"){
K6 += 1;
}
else if (data == "7"){
K7 += 1;
}
else if (data == "8"){
K8 += 1;
}
}}
void setup() {
Serial.begin(9600);
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(LED3_PIN, OUTPUT);
pinMode(LED4_PIN, OUTPUT);
pinMode(LED5_PIN, OUTPUT);
pinMode(LED6_PIN, OUTPUT);
pinMode(LED7_PIN, OUTPUT);
pinMode(LED8_PIN, OUTPUT);
xTaskCreatePinnedToCore(task1, "Task1", 1000, NULL, 1, NULL, APP_CPU_NUM);// Create tasks in the FreeRTOS environment on ESP32 and specify that the created task will run on a specific core of ESP32.
xTaskCreatePinnedToCore(task2, "Task2", 1000, NULL, 1, NULL, APP_CPU_NUM);
xTaskCreatePinnedToCore(task3, "Task3", 1000, NULL, 1, NULL, APP_CPU_NUM);
xTaskCreatePinnedToCore(task4, "Task4", 1000, NULL, 1, NULL, APP_CPU_NUM);// Create tasks in the FreeRTOS environment on ESP32 and specify that the created task will run on a specific core of ESP32.
xTaskCreatePinnedToCore(task5, "Task5", 1000, NULL, 1, NULL, APP_CPU_NUM);
xTaskCreatePinnedToCore(task6, "Task6", 1000, NULL, 1, NULL, APP_CPU_NUM);
xTaskCreatePinnedToCore(task7, "Task7", 1000, NULL, 1, NULL, APP_CPU_NUM);// Create tasks in the FreeRTOS environment on ESP32 and specify that the created task will run on a specific core of ESP32.
xTaskCreatePinnedToCore(task8, "Task8", 1000, NULL, 1, NULL, APP_CPU_NUM);
xTaskCreatePinnedToCore(task9, "Task9", 1000, NULL, 1, NULL, APP_CPU_NUM);
}
void loop() {}