изменения для лучшей работы

This commit is contained in:
KLASSENTS 2025-03-26 11:55:01 +07:00
parent a682dc80a9
commit 902d7b0932
4 changed files with 10 additions and 9 deletions

View File

@ -5,7 +5,7 @@
#include <Arduino_FreeRTOS.h> #include <Arduino_FreeRTOS.h>
const boolean valueToAssert = true; const bool valueToAssert = true;
// The setup function runs once when you press reset or power the board // The setup function runs once when you press reset or power the board
void setup() { void setup() {

View File

@ -102,6 +102,6 @@ void TaskAnalogRead(void *pvParameters) // This is a task.
int sensorValue = analogRead(A0); int sensorValue = analogRead(A0);
// print out the value you read: // print out the value you read:
Serial.println(sensorValue); Serial.println(sensorValue);
vTaskDelay(1); // one tick delay (15ms) in between reads for stability vTaskDelay(250 / portTICK_PERIOD_MS);
} }
} }

View File

@ -17,6 +17,8 @@
SemaphoreHandle_t mutex; SemaphoreHandle_t mutex;
int globalCount = 0; int globalCount = 0;
int task1Delay = 1250;
int task2Delay = 1000;
void setup() { void setup() {
@ -37,11 +39,11 @@ void setup() {
xTaskCreate(TaskMutex, // Task function xTaskCreate(TaskMutex, // Task function
"Task1", // Task name for humans "Task1", // Task name for humans
128, 128,
1000, // Task parameter &task1Delay, // Task parameter
1, // Task priority 1, // Task priority
NULL); NULL);
xTaskCreate(TaskMutex, "Task2", 128, 1000, 1, NULL); xTaskCreate(TaskMutex, "Task2", 128, &task2Delay, 1, NULL);
} }
@ -50,7 +52,6 @@ void loop() {}
void TaskMutex(void *pvParameters) void TaskMutex(void *pvParameters)
{ {
TickType_t delayTime = *((TickType_t*)pvParameters); // Use task parameters to define delay TickType_t delayTime = *((TickType_t*)pvParameters); // Use task parameters to define delay
for (;;) for (;;)
{ {
/** /**

View File

@ -72,15 +72,15 @@ void loop() {}
void TaskBlink(void *pvParameters){ void TaskBlink(void *pvParameters){
(void) pvParameters; (void) pvParameters;
pinMode(13,OUTPUT); pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(13,LOW); digitalWrite(LED_BUILTIN,LOW);
for(;;) for(;;)
{ {
digitalWrite(13,HIGH); digitalWrite(LED_BUILTIN,HIGH);
vTaskDelay(250/portTICK_PERIOD_MS); vTaskDelay(250/portTICK_PERIOD_MS);
digitalWrite(13,LOW); digitalWrite(LED_BUILTIN,LOW);
vTaskDelay(250/portTICK_PERIOD_MS); vTaskDelay(250/portTICK_PERIOD_MS);
} }
} }