Why won't this small program turn pin 13 on?

I am trying to modify an old IR program. I think I have all the new lines in that are required.
The program should just turn the pin 13 on and off every time I press my remote.

//www.elegoo.com

#include <IRremote.h>

//#define RECV_PIN  12        //Infrared signal receiving pin
  #define DECODE_SAMSUNG
  const byte IR_RECEIVE_PIN = 12; //  receive pin
#define LED       13        //define LED pin
#define L         16738455
#define UNKNOWN_L 1386468383

//bool state = LOW;           //define default input mode
int state=0;
unsigned long val;

//IRrecv irrecv(RECV_PIN);    //initialization
  //IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);//use pin 13
//decode_results results;     //Define structure type

//void stateChange() {
//  state = !state;
//  digitalWrite(LED, state);
//}

void setup() {
  pinMode(LED, OUTPUT); //initialize LED as an output
     IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);//use pin 13
  Serial.begin(9600);   // debug output at 9600 baud
  //irrecv.enableIRIn();  // Start receiving
}

void loop() {
  //  if (irrecv.decode(&results)) { 
        if (IrReceiver.decode()){
    val = IrReceiver.decodedIRData.command;
    Serial.println(val);
    //irrecv.resume();      // Receive the next value
       IrReceiver.resume(); // Enable receiving of the next value
    delay(150);
    //if(val == L || val == UNKNOWN_L) {
        if (val ==70)
        {
      stateChange();
       Serial.println(state);
      delay(5000);
    }
  }
}

void stateChange() {
  state = !state;
  digitalWrite(LED, state);
}

The relevant parts of the sketch are the alterations to the IR setup and the void stateChange().
If I press my remote I get the tx/rx led's and pin 13 led to flash, I get my monitor to show
70
1
and then
70
0
each time I press but according to the void stateChange I think I should get the led on 13 to come on and go off each time I press the remote which it does not do?
Can you see what I am doing wrong?

If I may give you a guess (I haven´t worked with IR yet), when you call this line:

you´re already making the LED on pin 13 responsive to command receiving. So, you don´t need your stateChange() function at all.

Comment these lines and try again:

Hi Brazilino, I am assuming the line

`IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);//use pin 13

just addresses pin 13 it won't turn it on or off every time I press the remote.
In fact doing as you say just stops any indication other than a flash of the tx/rx leds. I think I still need the void stateChange to turn the led on and off.

In fact if I change void stateChange to

void stateChange() {
  state = !state;
  digitalWrite(LED, HIGH);
  Serial.println(state);

then the led should come on when I press the remote.
I get a 1 or a 0 from

  Serial.println(state);

so it is reaching that line but the led 13 stays off?
If I put the blink sketch from examples in the led goes on and off so pin 13 is working

Ok, sorry. Reading the IR library docs I thought that ENABLE_LED_FEEDBACK would tell the library to blink the LED on pin 13 when receiving a signal. If so, your stateChange() routine would be changing the state and keeping the LED on when it was supposed to be off.

Another thing that you should keep in mind is that your sketch will be unresponsive for 5 seconds after receiving a 70 value:

All right, I tested the code below on Wokwi and it seems to be doing what you want:

#include <IRremote.h>
#define DECODE_SAMSUNG
const byte IR_RECEIVE_PIN = 12; //  receive pin
#define LED       13        //define LED pin
#define L         16738455
#define UNKNOWN_L 1386468383

//bool state = LOW;           //define default input mode
int state=0;
unsigned long val;


void setup() {
  pinMode(LED, OUTPUT); //initialize LED as an output
     IrReceiver.begin(IR_RECEIVE_PIN);//use pin 13
  Serial.begin(9600);   // debug output at 9600 baud
}

void loop() {
    if (IrReceiver.decode()){
    val = IrReceiver.decodedIRData.command;
    Serial.println(val);
    IrReceiver.resume(); // Enable receiving of the next value
    delay(150);
        if (val ==70) {
      stateChange();
       Serial.println(state);
      delay(5000);
    }
  }
}

void stateChange() {
  state = !state;
  digitalWrite(LED, state);
}

Would you mind to test it and report back?

This code should work very well.
But I didn't understand, (and it might get in the way), this delay he used of 5000 Ms.

#include <IRremote.h>
#define DECODE_SAMSUNG
const byte IR_RECEIVE_PIN = 12; //  receive pin
#define LED       13        //define LED pin
#define L         16738455
#define UNKNOWN_L 1386468383

//bool state = LOW;           //define default input mode
int state=0;
unsigned long val;


void setup() {
  pinMode(LED, OUTPUT); //initialize LED as an output
     IrReceiver.begin(IR_RECEIVE_PIN);//use pin 13
  Serial.begin(9600);   // debug output at 9600 baud
}

void loop() {
    if (IrReceiver.decode()){
    val = IrReceiver.decodedIRData.command;
    Serial.println(val);
    //IrReceiver.resume(); // Enable receiving of the next value
    delay(150);
        if (val ==70) {
      stateChange();
       Serial.println(state);
      delay(1000);
    }
    IrReceiver.resume(); // Enable receiving of the next value
  }
}

void stateChange() {
  state = !state;
  digitalWrite(LED, state);
}

I altered the sketch you posted slightly to the one above.
I commented out the line
IrReceiver.resume(); // Enable receiving of the next value
because it allows the next remote push to be read as it says in the comment at the end of the line.
I moved it to the end of the sequence.

I have used this because I keep getting double signals and I assume it is because I am holding the remote button too long.
Moving the IrReceiver.resume(); helps but the delay just ensures I can stop pressing before it gets a second signal.
I have been experimenting with adding the void stateChange into other sketches to see if it works, without success.
For some reason it now works in the sketch above?
At this point I have no idea what I have been doing different.
It is getting late now and I have commitments tomorrow so I will have another look tomorrow evening.
I will come back to you then.
The sketch I want ultimately is this one

#include <IRremote.h>
#include <Servo.h>  

#define f 16736925  // FORWARD
#define b 16754775  // BACK
#define l 16720605  // LEFT
#define r 16761405  // RIGHT
#define s 16712445  // STOP
#define KEY1 16738455 //Line Teacking mode
#define KEY2 16750695 //Obstacles Avoidance mode
#define KEY3 16756815
#define KEY4 16724175
#define KEY5 16718055
#define KEY6 16743045
#define KEY7 16716015
#define KEY8 16726215
#define KEY9 16734885
#define KEY0 16730805
#define KEY_STAR 16728765
#define KEY_HASH 16732845

//#define RECV_PIN  12
#define IR_RECEIVE_PIN  12
#define ECHO_PIN  A4  
#define TRIG_PIN  A5 
#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11
#define LED_Pin 13
#define LineTeacking_Pin_Right  10
#define LineTeacking_Pin_Middle 4
#define LineTeacking_Pin_Left   2
#define LineTeacking_Read_Right   !digitalRead(10)
#define LineTeacking_Read_Middle  !digitalRead(4)
#define LineTeacking_Read_Left    !digitalRead(2)
#define carSpeed 250

Servo servo;
//IRrecv irrecv(RECV_PIN);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);//use pin 13
//decode_results results;
unsigned long IR_PreMillis;
unsigned long LT_PreMillis;
int rightDistance = 0, leftDistance = 0, middleDistance = 0;

enum FUNCTIONMODE{
  IDLE,
  LineTeacking,
  ObstaclesAvoidance,
  Bluetooth,
  IRremote
} func_mode = IDLE;

enum MOTIONMODE {
  STOP,
  FORWARD,
  BACK,
  LEFT,
  RIGHT
} mov_mode = STOP;

void delays(unsigned long t) {
  for(unsigned long i = 0; i < t; i++) {
    getBTData();
    getIRData();
    delay(1);
  }
}

int getDistance() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  return (int)pulseIn(ECHO_PIN, HIGH) / 58;
}

void forward(bool debug = false){ 
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  if(debug) Serial.println("Go forward!");
}

void back(bool debug = false){
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  if(debug) Serial.println("Go back!");
}

void left(bool debug = false){
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH); 
  if(debug) Serial.println("Go left!");
}

void right(bool debug = false){
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  if(debug) Serial.println("Go right!");
}

void stop(bool debug = false){
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
  if(debug) Serial.println("Stop!");
}

void getBTData() {
  if(Serial.available()) {
    switch(Serial.read()) {
      case 'f': func_mode = Bluetooth; mov_mode = FORWARD;  break;
      case 'b': func_mode = Bluetooth; mov_mode = BACK;     break;
      case 'l': func_mode = Bluetooth; mov_mode = LEFT;     break;
      case 'r': func_mode = Bluetooth; mov_mode = RIGHT;    break;
      case 's': func_mode = Bluetooth; mov_mode = STOP;     break;
      case '1': func_mode = LineTeacking;                   break;
      case '2': func_mode = ObstaclesAvoidance;             break;
      default:  break;
    } 
  }
}

void getIRData() {
  //if (irrecv.decode(&results)){ 
      if (IrReceiver.decode()){
    IR_PreMillis = millis();
    //switch(results.value){
      val = IrReceiver.decodedIRData.command;
      switch(val);
      case f:   func_mode = IRremote; mov_mode = FORWARD;  break;
      case b:   func_mode = IRremote; mov_mode = BACK;     break;
      case l:   func_mode = IRremote; mov_mode = LEFT;     break;
      case r:   func_mode = IRremote; mov_mode = RIGHT;    break;
      case s:   func_mode = IRremote; mov_mode = STOP;     break;
      case KEY1:  func_mode = LineTeacking;                break;
      case KEY2:  func_mode = ObstaclesAvoidance;          break;
      default: break;
    }
    //irrecv.resume();
         delay(1500);
    IrReceiver.resume();
  }
}

void bluetooth_mode() {
  if(func_mode == Bluetooth){
    switch(mov_mode){
      case FORWARD: forward();  break;
      case BACK:    back();     break;
      case LEFT:    left();     break;
      case RIGHT:   right();    break;
      case STOP:    stop();     break;
      default: break;
    }
  }
}

void irremote_mode() {
  if(func_mode == IRremote){
    switch(mov_mode){
      case FORWARD: forward();  break;
      case BACK:    back();     break;
      case LEFT:    left();     break;
      case RIGHT:   right();    break;
      case STOP:    stop();     break;
      default: break;
    }
    if(millis() - IR_PreMillis > 500){
      mov_mode = STOP;
      IR_PreMillis = millis();
    }
  }   
}

void line_teacking_mode() {
  if(func_mode == LineTeacking){
    if(LineTeacking_Read_Middle){
      forward();
      LT_PreMillis = millis();
    } else if(LineTeacking_Read_Right) { 
      right();
      while(LineTeacking_Read_Right) {
        getBTData();
        getIRData();
      }
      LT_PreMillis = millis();
    } else if(LineTeacking_Read_Left) {
      left();
      while(LineTeacking_Read_Left) {
        getBTData();
        getIRData();
      }
      LT_PreMillis = millis();
    } else {
      if(millis() - LT_PreMillis > 150){
        stop();
      }
    }
  }  
}

void obstacles_avoidance_mode() {
  if(func_mode == ObstaclesAvoidance){
    servo.write(90);
    delays(500);
    middleDistance = getDistance();
    if(middleDistance <= 40) {
      stop();
      delays(500);
      servo.write(10);
      delays(1000);
      rightDistance = getDistance();
      
      delays(500);
      servo.write(90);
      delays(1000);
      servo.write(170);
      delays(1000); 
      leftDistance = getDistance();
      
      delays(500);
      servo.write(90);
      delays(1000);
      if(rightDistance > leftDistance) {
        right();
        delays(360);
      } else if(rightDistance < leftDistance) {
        left();
        delays(360);
      } else if((rightDistance <= 40) || (leftDistance <= 40)) {
        back();
        delays(180);
      } else {
        forward();
      }
    } else {
        forward();
    }  
  }  
}

void setup() {
  Serial.begin(9600);
  servo.attach(3,500,2400);// 500: 0 degree  2400: 180 degree
  servo.write(90);
  irrecv.enableIRIn();
  pinMode(ECHO_PIN, INPUT);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(LineTeacking_Pin_Right, INPUT);
  pinMode(LineTeacking_Pin_Middle, INPUT);
  pinMode(LineTeacking_Pin_Left, INPUT);
}

void loop() {
  getBTData();
  getIRData();
  bluetooth_mode();
  irremote_mode();
  line_teacking_mode();
  obstacles_avoidance_mode();
}

It comes from an old robot but it uses the old IR lines and I am trying to convert it to the new. So far I have almost got it but when I compile the above sketch I get
Compilation error: 'IrReceiver' does not name a type
now I can use the stateChange lines I can continue the try to find the bug.
Tomorrow.