#include <Arduino_FreeRTOS.h>
#include <semphr.h>

SemaphoreHandle_t Semaphoret1;

void task1(void *parameter) {
  while (1) {
    if (xSemaphoreTake(Semaphoret1, pdMS_TO_TICKS(1000)) == pdTRUE) {
      Serial.println("Lab 1");
      xSemaphoreGive(Semaphoret1);
    }
  }
}

void task2(void *parameter) {
  while (1) {
    if (xSemaphoreTake(Semaphoret1, pdMS_TO_TICKS(5000)) == pdTRUE) {
      Serial.println("RTES Lab");
      xSemaphoreGive(Semaphoret1);
    }
  }
}

void setup() {
  Serial.begin(9600);
  //delay(1000); 
  Semaphoret1 = xSemaphoreCreateBinary();
  if (Semaphoret1 != NULL) {
    xSemaphoreGive(Semaphoret1); 
  }
  xTaskCreate(task1, "Task 1", 256, NULL, 1, NULL);
  xTaskCreate(task2, "Task 2", 256, NULL, 1, NULL);
  vTaskStartScheduler();
}

void loop() {
  // Empty loop, FreeRTOS handles task scheduling
}