Problem with tasks and printing with a simple airport control in Arduino

Hello. I am very very new to programming so I may have committed very dumb mistakes, but I’ve been trying to make a simple code to emulate the runway and take off of a plane in an airport by using push buttons in Arduino.

In theory it should close the runway when the first button is pressed and print its state which would be 0 once. Then a plane would take off when the second button is pressed, turn on a LED for 1 second and open the runway again.

Problem is, the second task regarding the take off doesn’t even work, even though as far as I know the tasks have the same priority and the don’t even interact with each other. Also the printing of the runway state seems to happen as long as the button is held for which I guess is 1ms, even though it should only be printed once with the task delay after the function.

Any help would be greatly appreciated.
(for some reason I cannot post links, but the ID of the project in Wokwi is 384041557583023105)

#include <Arduino_FreeRTOS.h>

int ledPin = 11;
int authorization = 1;
int takeoff = 1;

static int runway = true;                   //state of the runway (open/closed)

const int authoPin = 12;  
const int takeoffPin = 8;

void Authorization(void *pvParameters) {
  authorization = digitalRead(authoPin);
  if (authorization == 0) {                 //if the first button is pressed 
    runway = false;                         //close the runway
    Serial.println(runway);                 //print state of the runway

void TakeOff(void *pvParameters) {
  takeoff = digitalRead(takeoffPin);
  if (takeoff == 0) {                       //if the second button is pressed
    Serial.println(runway);                 //print state of the runway
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin, LOW);
    runway = true;                         //open the runway again
    Serial.println(runway);                //print state of the runway

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(authorization, INPUT_PULLUP);
pinMode(takeoff, INPUT_PULLUP);

xTaskCreate (Authorization, "Authorization", 128, NULL, 1, NULL);   
xTaskCreate (TakeOff, "TakeOff", 128, NULL, 1, NULL);

void loop() {

Tasks must NOT return to their caller, but should have a while(1) loop so they keep running, and if they actually finish, delete themselves.

Also, tasks should “block” in this loop, perhaps put in a vTaskDelay(1) to wait for the next tick, to let control pass from one task to the next.

You likely also, to be a better simulation, should only accept an authorization if the runway is actually open, and a takeoff if it is closed

Hello, I put a while(1) in each task and it worked perfectly. Thank you very much.