Arduino FreeRTOS code flip

Hello to everyone; I have my arduino code written in my c language.I need to write FreeRTOS code that performs the same function. How should I make a conversion? Where can I find out? ~~~

include<Servo.h>

const int sensorMin = 0; // sensor minimum const int sensorMax = 1024; // sensor maximum int speakerPin = 3; Servo sg90; void setup() { // initialize serial communication @ 9600 baud: Serial.begin(9600); pinMode (speakerPin, OUTPUT); sg90.attach(7); } void loop() { // read the sensor on analog A0: int sensorReading = analogRead(A0); // map the sensor range (four options): // ex: ‘long int map(long int, long int, long int, long int, long int)’ int range = map(sensorReading, sensorMin, sensorMax, 0, 3); // range value: switch (range) { case 0: // A fire closer than 1.5 feet away. Serial.println(“** Close Fire “); analogWrite (speakerPin, 50); sg90.write(180); break; case 1: // A fire between 1-3 feet away. Serial.println(“ Distant Fire **”); analogWrite (speakerPin, 255); sg90.write(0); break; } delay(1); // delay between reads } ~~~

Arduino FreeRTOS code flip

I’ve set task1. But I have to move the buzzer and servo control I have on task 1 to task 2. But when I carry the codes, the buzzer works continuously and doesn’t move according to the data. ~~~

include <Arduino_FreeRTOS.h>

include <Servo.h>

const int sensorMin = 0; // sensor minimum const int sensorMax = 1024; // sensor maximum int speakerPin = 3; Servo sg90; int range; void setup() { Serial.begin(9600); pinMode (speakerPin, OUTPUT); sg90.attach(7); xTaskCreate(Task1,”Sensor”, 100, NULL, 1, NULL); xTaskCreate(Task2,”Servo Motor”, 100, NULL, 0, NULL); } void loop() { // put your main code here, to run repeatedly: } void Task1(void *pvParameters) { for(;;) { int sensorReading = analogRead(A0); vTaskDelay(2/portTICK_PERIOD_MS); range = map(sensorReading, sensorMin, sensorMax, 0, 3); vTaskDelay(10/portTICK_PERIOD_MS); if(range==0) { Serial.println(“** Close Fire **”); analogWrite (speakerPin, 50); sg90.write(180); }
if(range==1)
{
  Serial.println("** Distant Fire **");
  analogWrite(speakerPin, 255);
  sg90.write(0);
}
} } void Task2(void *pvParameters) { vTaskDelay(20/portTICK_PERIOD_MS); for(;;) {
vTaskDelay(20/portTICK_PERIOD_MS);
} } ~~~

Arduino FreeRTOS code flip

I have no idea about Arduino, but from what I can see from your original post…. The code that is is setup() can be code that appears in main() before the scheduler is started. The code that is in loop can be added to a task that uses vTaskDelayUntil() (https://www.freertos.org/vtaskdelayuntil.html ) to control the period of its execution – unless delay(1) is very short, in which just run the task at the idle priority so it doesn’t starve out higher priority tasks and call vTaskDelay( 1 ) instead of vTaskDelayUntil(). In your second post you added a couple of extra delays around the call to map() – not sure why, but if you are waiting for the map() operation to complete, then it would be better to block on an event primitive, such as a direct to task notification, so the delay is exactly as long as the operation takes rather than choosing an arbitrary block time (https://www.freertos.org/RTOS-task-notifications.html ).