#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
QueueHandle_t xQueue1;
// Task function
void StartTask1(void *pvParameters) {
while (1) {
// Read the potentiometer value (0 to 1023)
long potValue = analogRead(A0);
// Map the potentiometer value to the LED brightness range (0 to 255)
long brightness = map(potValue, 0, 1023, 0, 255);
digitalWrite(8, HIGH);
vTaskDelay(500);
digitalWrite(8, LOW);
vTaskDelay(500);
xQueueSend(xQueue1, &brightness, 10);
}
}
// Task function
void StartTask2(void *pvParameters) {
while (1) {
long data;
long duty;
//digitalWrite(9, HIGH);
//vTaskDelay(1000);
//digitalWrite(9, LOW);
xQueueReceive(xQueue1, &data, 10);
// Set the LED brightness
analogWrite(6,data);
Serial.println(data);
vTaskDelay(1000);
}
}
void setup() {
// put your set6up code here, to run once:
Serial.begin(115200);
pinMode(8, OUTPUT);
pinMode(6, OUTPUT);
// Create a queue
xQueue1 = xQueueCreate(10, sizeof(long));
// Create a task with a priority of 1
xTaskCreate(StartTask1, "Task1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(StartTask2, "Task2", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
// Start the scheduler
vTaskStartScheduler();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}