// #include "esp_log.h"
// #include "stdio.h"
// #define TAG "Teste Log"

// #define CONFIG_LOG_DEFAULT_LEVEL_VERBOSE 1
// #define CONFIG_LOG_DEFAULT_LEVEL 5
// #define CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE 1
// #define CONFIG_LOG_MAXIMUM_LEVEL 5
// #define CONFIG_LOG_COLORS 1
// #define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1 

TaskHandle_t Task1;
TaskHandle_t Task2;
#define blinkPeriod 200
#define task1Core 0
#define task2Core 0

// LED pins
const int led1 = 12;
const int led2 = 13;

void setup() {
  Serial.begin(115200);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  //esp_log_level_set(TAG, ESP_LOG_VERBOSE);

  //create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
  xTaskCreatePinnedToCore(
    Task1code,   /* Task function. */
    "Task1",     /* name of task. */
    10000,       /* Stack size of task */
    NULL,        /* parameter of the task */
    1,           /* priority of the task */
    &Task1,      /* Task handle to keep track of created task */
    task1Core);          /* pin task to core 0 */
  //delay(500);

  //create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
  xTaskCreatePinnedToCore(
    Task2code,   /* Task function. */
    "Task2",     /* name of task. */
    10000,       /* Stack size of task */
    NULL,        /* parameter of the task */
    1,           /* priority of the task */
    &Task2,      /* Task handle to keep track of created task */
    task2Core);          /* pin task to core 1 */
  //delay(500);
}

//Task1code: blinks an LED every 1000 ms
void Task1code( void * pvParameters ) {
  //Serial.print("Task1 running on core ");
  //Serial.println(xPortGetCoreID());

  for (;;) {
    unsigned long tNow = millis();
    digitalWrite(led1, HIGH);
    delay(blinkPeriod);
    digitalWrite(led1, LOW);
    delay(blinkPeriod);
    Serial.print("Task1: ");Serial.println(millis()-tNow);
  }
}

//Task2code: blinks an LED every 700 ms
void Task2code( void * pvParameters ) {
  //Serial.print("Task2 running on core ");
  //Serial.println(xPortGetCoreID());

  for (;;) {
    unsigned long tNow = millis();
    digitalWrite(led2, HIGH);
    delay(blinkPeriod);
    digitalWrite(led2, LOW);
    delay(blinkPeriod);
    Serial.print("Task2: ");Serial.println(millis()-tNow);
  }
}

void loop() {
  /* Serial.print("Task2 running on core ");
  Serial.println(xPortGetCoreID());

  for (;;) {
    digitalWrite(led2, HIGH);
    delay(700);
    digitalWrite(led2, LOW);
    delay(700);
  } */

}