Programing error, xTaskCreatePinnedToCore + was not declared in this scope

Hello everyone! Plese help me! I have problem with 2 core programming esp32 wroom 32d.
Arduino ide compiles code, but PlatformIO does’t work and say ‘task1code’ was not declared in this scope and ‘task2code’ was not declared in this scope.
Code here:

        #include <Arduino.h>
    #include <FreeRTOS.h>

    TaskHandle_t Task1, Task2;

    const uint8_t led1 = 2;
    const uint8_t led2 = 5;

    void setup() {

    Serial.begin(115200);

    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);

    xTaskCreatePinnedToCore(
                task1code,
                "Task1",
                10000,
                NULL,
                1,
                &Task1,
                0);
    xTaskCreatePinnedToCore(
                task2code,
                "Task2",
                10000,
                NULL,
                1,
                &Task2,
                1);
    }

    void loop(){
    }

    void task1code (void * pvParameters){
        for(;;){
          digitalWrite(led1, HIGH);
          delay(1000);
          digitalWrite(led1,LOW);
          delay(1000);
        }

    }

    void task2code (void * pvParameters){
          for(;;){
          digitalWrite(led2, HIGH);
          delay(700);
          digitalWrite(led2,LOW);
          delay(700);
        }

    }

The Arduino IDE does a lot of stuff for you in the background. One thing it does is to scan your code looking for functions that are defined after their use, like your task1code and task2code.

If it finds any, it attempts to declare those functions at the top, before their use. In PlatformIO, you need to do this yourself.

Change the top of your code to this:

#include <Arduino.h>
#include <FreeRTOS.h>

void task1code (void * pvParameters);
void task2code (void * pvParameters);
...

The compiler now knows about your two tasks, before it finds references or calls to them while compiling your source.

You might find this useful: Tutorial for creating multi cpp file arduino project - #38 by NormanDunbar.

Cheers,
Norm.

Thanks! It’s work. :+1: . Sorry, I stady to learn C++.

No apology necessary. Many people new to microcontrollers etc, don’t actually know what the Arduino IDE is doing in the background, and hidden from you, to make your life easy. The problems occur when you move away from the Arduino IDE onto something else, PlatformIO, Atmel Studio etc, and suddenly, you are in control and have to do everything correctly and in a completely different manner from what you used to do in the Arduino IDE.

The Arduino way of working is great, as long as you stay in the Arduino environment, once you move away, it’s not so helpful.

Cheers,
Norm.