Question about NRF 24l01 controlling a LED

Hi, I’m having the same problem as in the topic mentioned above but I don’t know how OP fixed it, when I upload the code the LED stays on.

#include <SPI.h>                       // SPI Arayüzünü dahil ettik.
#include "RF24.h"                      // RF24 kütüpanelerini dahil ettik.
byte data[1];                          // Göndereceğimiz data değişkenini oluşturduk.
boolean var;                           // Bit şeklinde var değişkeninini oluşturduk.
const uint64_t pipe = 0xF0F0F0F0A1LL;  // Paralel veri yolu adresleri tanımlamasını yaptık.
RF24 radio(9,10);                      // Modülün CE pinini 9.pin CS pinini de 10.pine bağlayacağımızı belirttik.
int ledPin = 3;
 
boolean currentButton = LOW;
boolean lastButton = LOW;
boolean ledOn = false;
 
boolean debounce(boolean last)
{
   boolean current =digitalRead(ledPin);
   if (current != lastButton)
   {
      delay(5);
      current = digitalRead(ledPin);
   }
   return current;
}
 

void setup(){
 //pinMode(3, OUTPUT);                    // Arduino'nun 2.pinini çıkış olarak ayarladık.
                   
pinMode(ledPin, OUTPUT);
 radio.begin();                         // Kablosuz iletişimi başlattık.
 radio.openReadingPipe(1,pipe);         // Veri alacağımız kanalın ID'sini tanımladık.
 radio.startListening();                
}

void loop(){
 if(radio.available()){
   var = false;
   while(!var){
     var = 
     radio.read(data, 1);   
      //if(data[0] == 0){
      //digitalWrite(3, LOW);
                                                            // digitalWrite(4, LOW);
     // }
      if(data[0] == 1){
      digitalWrite(ledPin, LOW);
      }
      if(data[0] == 2){
      digitalWrite(ledPin, HIGH);
      }
   }
 }
 else
   
   delay(100);
currentButton = debounce(lastButton);
 
   if (currentButton == LOW && lastButton == HIGH) ledOn = !ledOn;
 
   lastButton = currentButton;
 
   digitalWrite(ledPin, ledPin);

 
  }

Does somebody have any suggestions?

Does somebody have any suggestions?

You bet.

byte data[1];                          // Göndereceğimiz data değişkenini oluşturduk.

One element arrays are pretty dumb. Don't create them.

boolean debounce(boolean last)
{
   boolean current =digitalRead(ledPin);
   if (current != lastButton)
   {
      delay(5);
      current = digitalRead(ledPin);
   }
   return current;
}

How is an LED supposed to turn that pin on or off?

If you are using pin 3 as an OUTPUT pin (you are not, or you wouldn't have commented out the pin mode statement), output pins don't bounce.

   digitalWrite(ledPin, !ledPin);

Set the state of this pin, unconditionally, to not 3. An interesting approach, to be sure.

You have code that sets the state of the pin conditionally, based on input from the radio, and unconditionally. Do NOT do that. Make up your mind what controls the state of the pin, and delete ALL other code that f**ks with the state of the pin.