How to modify IR sketch for continuous motion when holding down Direction Keys?

Hello, I am trying how to figure out how to modify this IR sketch to get continuous motor motion when holding down the directional keys on my IR remote. Any help would be greatly appreciated.

#include <IRremote.h>
#include <Servo.h>
/Define L298N Dual H-Bridge Motor Controller Pins/
#define IN1 8 //K1、K2 motor direction
#define IN2 9 //K1、K2 motor direction
#define IN3 10 //K3、K4 motor direction
#define IN4 12 //K3、K4 motor direction
#define ENA 5 // Needs to be a PWM pin to be able to control motor speed ENA
#define ENB 6 // Needs to be a PWM pin to be able to control motor speed ENB
#define SERVO 11 //servo(SG90) connect to D11
#define LED1 2 //lefe led connect to D2
#define LED2 3 //right led connect to D3
#define IRPIN 13 //IR receiver Signal pin connect to Arduino pin 13
#define BUZZER 7 //buzzer connect D7

#define IR_ADVANCE 0x00FF18E7 //code from IR controller “▲” button
#define IR_BACK 0x00FF4AB5 //code from IR controller “▼” button
#define IR_RIGHT 0x00FF5AA5 //code from IR controller “>” button
#define IR_LEFT 0x00FF10EF //code from IR controller “<” button
#define IR_SERVO 0x00FF38C7 //code from IR controller “OK” button
#define IR_OPENLED 0x00FFB04F //code from IR controller “#” button
#define IR_CLOSELED 0x00FF6897 //code from IR controller “*” button
#define IR_BEEP 0x00FF9867 //code from IR controller “0” button

enum DN
{
GO_ADVANCE, //go ahead
GO_LEFT, //left turn
GO_RIGHT,//right turn
GO_BACK,//go back
MOVE_SERVO,//move servo
OPEN_LED,//open led
CLOSE_LED,//close led
BEEP,//control buzzer
DEF
}Drive_Num=DEF;

Servo head;
IRrecv IR(IRPIN); // IRrecv object IR get code from IR remoter
decode_results IRresults;
bool stopFlag = true;//set stop flag
bool JogFlag = false;
uint16_t JogTimeCnt = 0;
uint32_t JogTime=0;
/motor control/
void go_ahead(int t)//go ahead
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4,HIGH);
delay(t);
}
void go_back(int t) //go back
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4,LOW);
delay(t);
}
void go_stop() //stop
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4,LOW);
}
void turn_left(int t)//turn left
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(t);
}
void turn_right(int t)//turn right
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
delay(t);
}
/*set motor speed /
void set_motorspeed(int lspeed,int rspeed)
{
analogWrite(ENA,lspeed);
analogWrite(ENB,rspeed);
}
/control led/
void open_led(int led_num)
{
if (led_num == 1) digitalWrite(LED1,LOW);
else digitalWrite(LED2,LOW);
}
void close_led(int led_num)
{
if (led_num == 1) digitalWrite(LED1,HIGH);
else digitalWrite(LED2,HIGH);
}
/control buzzer/
void control_beep()
{
digitalWrite(BUZZER,LOW),delay(100);
digitalWrite(BUZZER,HIGH),delay(100);
}
/move servo/
void move_servo()
{
int i;
for(i = 0;i<180;i++){
head.write(i);
delay(5);
}
for(i = 180;i>=0;i–){
head.write(i);
delay(5);
}
head.write(90);
}
/detect IR code
/
void do_IR_Tick()
{
if(IR.decode(&IRresults))
{
if(IRresults.value==IR_ADVANCE)
{
Drive_Num=GO_ADVANCE;
}
else if(IRresults.value==IR_RIGHT)
{
Drive_Num=GO_RIGHT;
}
else if(IRresults.value==IR_LEFT)
{
Drive_Num=GO_LEFT;
}
else if(IRresults.value==IR_BACK)
{
Drive_Num=GO_BACK;
}
else if(IRresults.value==IR_SERVO)
{
Drive_Num=MOVE_SERVO;
}
else if(IRresults.value==IR_OPENLED)
{
Drive_Num=OPEN_LED;
}
else if(IRresults.value==IR_CLOSELED)
{
Drive_Num=CLOSE_LED;
}
else if(IRresults.value==IR_BEEP)
{
Drive_Num=BEEP;
}
IRresults.value = 0;
IR.resume();
}
}
/car control/
void do_Drive_Tick()
{
switch (Drive_Num)
{
case GO_ADVANCE:
go_ahead(10);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_ADVANCE code is detected, then go advance
case GO_LEFT:
turn_left(10);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_LEFT code is detected, then turn left
case GO_RIGHT:
turn_right(10);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_RIGHT code is detected, then turn right
case GO_BACK:
go_back(10);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_BACK code is detected, then backward
case MOVE_SERVO:
move_servo();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//move servo
case OPEN_LED:
open_led(1),open_led(2);JogTime = 0;break;//open led
case CLOSE_LED:
close_led(1),close_led(2);JogTime = 0;break;//close led
case BEEP:
control_beep();JogTime = 0;break;//control beep
default:break;
}
Drive_Num=DEF;
//keep current moving mode for 300 millis seconds
if(millis()-JogTime>=300)
{
JogTime=millis();
if(JogFlag == true)
{
stopFlag = false;
if(JogTimeCnt <= 0)
{
JogFlag = false; stopFlag = true;
}
JogTimeCnt–;
}
if(stopFlag == true)
{
JogTimeCnt=0;
go_stop();
}
}
}
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(BUZZER, OUTPUT);
head.attach(SERVO);
close_led(1),close_led(2);//close led
digitalWrite(BUZZER,HIGH);//close buzzer
pinMode(IRPIN, INPUT);
digitalWrite(IRPIN, HIGH);
IR.enableIRIn();
set_motorspeed(160,160);
go_stop();
}

void loop() {
do_IR_Tick();
do_Drive_Tick();
}

Have you checked what code(s) are sent when you hold down a key on the IR remote? A lot of them will send a common REPEAT code meaning in effect "the last key a code was sent for is still held down".

Steve

Thanks for the reply, I figured it out earlier today. here is the code i added to (detect IR code Heading) to make it work.

    if (IRresults.value == 0xFFFFFFFF)
    {
      // If Repeat then use last code recieved
      IRresults.value = lastcode;
    }
    if (IRresults.value == IR_ADVANCE)
    {
      //code from IR controller "▲" button
      lastcode = IRresults.value;
    }
    if (IRresults.value == IR_RIGHT)
    {
      //code from IR controller ">" button
      lastcode = IRresults.value;
    }
    if (IRresults.value == IR_LEFT)
    {
      //code from IR controller "<" button
      lastcode = IRresults.value;
    }
    if (IRresults.value == IR_BACK)
    {
      //code from IR controller "▼" button
      lastcode = IRresults.value;
    }