IR remote command is stuck in While loop ! help me plz

No that will not work long term. For each of your case statements with a long delay in them there will be as many pending function enable flags to check before you can consider going to your switch statement again with a new IR command to decode.

What did I say about building things up slowly?

The is a whole new style of programming and you can't just slap a sticking plaster over it.

So we need to see the code so far.

I have no idea what this means.

Remember you algorithm function still needs mending.

here is the code

#include <IRremote.h>
#define PIN_RECEIVER A0

int Lane1[] = {13,12,11}; // Lane 1 Red, Yellow and Green
int Lane2[] = {10,9,8};// Lane 2 Red, Yellow and Green
int Lane3[] = {7,6,5};// Lane 3 Red, Yellow and Green
int Lane4[] = {4,3,2};// Lane 4 Red, Yellow and Green
boolean task48aEnable;
boolean task24aEnable;
boolean task122aEnable;
boolean task16aEnable;
unsigned long int runTask48a;
IRrecv receiver(PIN_RECEIVER);
decode_results results;      

void setup() 
{
  receiver.enableIRIn();
  for (int i = 0; i < 3; i++)
  {
    pinMode(Lane1[i], OUTPUT); 
    pinMode(Lane2[i], OUTPUT);
    pinMode(Lane3[i], OUTPUT);
    pinMode(Lane4[i], OUTPUT);
  }
}

void loop() 
{  
  
  if (receiver.decode()) 
  {
      translateIR();
      receiver.resume();  // Receive the next value
  }
  if( task48aEnable == true and millis() > runTask48a)
  {
    if(receiver.decodedIRData.command==48)
    {
      task48a();
    }
  } 
  if( task24aEnable == true and millis() > runTask48a)
  {
    if(receiver.decodedIRData.command==24)
    {
      task24a();
    }
  }
  if( task122aEnable == true and millis() > runTask48a)
  {
    if(receiver.decodedIRData.command==122)
    {
      task122a();
    }
  } 
  if( task16aEnable == true and millis() > runTask48a)
  {
    if(receiver.decodedIRData.command==16)
    {
      task16a();
    }
  }
}
void task48a(){
       digitalWrite(Lane1[1], LOW);
       digitalWrite(Lane1[2], HIGH); //lane 1-Green
          task48aEnable = false;  // do not run this task again until enabled          
}
void task24a(){
       digitalWrite(Lane3[1], LOW);
  	   digitalWrite(Lane3[2], HIGH); //lane 3-Green
          task24aEnable = false;
          //runTask24a = 0;  // do not run this task again until enabled
}
void task122a(){
       digitalWrite(Lane4[1], LOW);
  	   digitalWrite(Lane4[2], HIGH); //lane 4-Green
          task122aEnable = false;  // do not run this task again until enabled          
}
void task16a(){
       digitalWrite(Lane2[1], LOW);
  	   digitalWrite(Lane2[2], HIGH); //lane 2-Green
          task16aEnable = false;  // do not run this task again until enabled          
}
void translateIR()
{
  // Takes command based on IR code received
  switch (receiver.decodedIRData.command) {
    case 48:
    //Keypad button "1"     
         //Lane 1 - Green
      digitalWrite(Lane1[0], LOW);
	    digitalWrite(Lane1[2], LOW);
	    digitalWrite(Lane1[1], HIGH); //lane 1-Yellow
	    digitalWrite(Lane3[1], LOW);
	    digitalWrite(Lane3[2], LOW);
  	  digitalWrite(Lane3[0], HIGH); //lane 3-Red
	    digitalWrite(Lane4[1], LOW);
	    digitalWrite(Lane4[2], LOW); 
  	  digitalWrite(Lane4[0], HIGH); //lane 4-Red
	    digitalWrite(Lane2[1], LOW);
	    digitalWrite(Lane2[2], LOW);
  	  digitalWrite(Lane2[0], HIGH); //lane 2-red
	    task48aEnable = true; // this is a global boolean variable.
      runTask48a = millis() + 3000; // this is a global unsigned long int
      break; 
    case 24:
      //Keypad button "2"     
         //Lane 3 - Green
	    digitalWrite(Lane4[1], LOW);
	    digitalWrite(Lane4[2], LOW); 
  	  digitalWrite(Lane4[0], HIGH);  //lane 4-Red
	    digitalWrite(Lane2[1], LOW);
	    digitalWrite(Lane2[2], LOW);
  	  digitalWrite(Lane2[0], HIGH);  //lane 2-Red   
      digitalWrite(Lane1[2], LOW);
	    digitalWrite(Lane1[1], LOW);
	    digitalWrite(Lane1[0], HIGH); 	//lane 1-Red	
	    digitalWrite(Lane3[0], LOW);
	    digitalWrite(Lane3[2], LOW);	
  	  digitalWrite(Lane3[1], HIGH);	//lane 3-Yellow
  	  task24aEnable = true;
      runTask48a = millis() + 3000;   
      break;
    case 122:
      //Keypad button "3"     
          //Lane 4 - Green
	    digitalWrite(Lane4[2], LOW); 
  	  digitalWrite(Lane4[0], LOW);
	    digitalWrite(Lane4[1], HIGH);  //lane 4-Yellow
	    digitalWrite(Lane2[1], LOW);
	    digitalWrite(Lane2[2], LOW);
  	  digitalWrite(Lane2[0], HIGH);  //lane 2-Red   
      digitalWrite(Lane1[2], LOW);
	    digitalWrite(Lane1[1], LOW);
	    digitalWrite(Lane1[0], HIGH); 	//lane 1-Red	
	    digitalWrite(Lane3[1], LOW);
	    digitalWrite(Lane3[2], LOW);	
  	  digitalWrite(Lane3[0], HIGH);	 //lane 3-Red
      task122aEnable = true;
      runTask48a = millis() + 3000;   
      break; 
    case 16:
      //Keypad button "4"     
         //Lane 2 - green     
      digitalWrite(Lane4[2], LOW); 
  	  digitalWrite(Lane4[1], LOW);
	    digitalWrite(Lane4[0], HIGH);  //lane 4-Red
	    digitalWrite(Lane2[0], LOW);
	    digitalWrite(Lane2[2], LOW);
  	  digitalWrite(Lane2[1], HIGH);  //lane 2-Yellow   
      digitalWrite(Lane1[2], LOW);
	    digitalWrite(Lane1[1], LOW);
	    digitalWrite(Lane1[0], HIGH); 	//lane 1-Red	
	    digitalWrite(Lane3[1], LOW);
	    digitalWrite(Lane3[2], LOW);	
  	  digitalWrite(Lane3[0], HIGH);	//lane 3-Red
      task16aEnable = true;
      runTask48a = millis() + 3000;
      break;
    case 162:
    //Power button
    // All Lane goes OFF
      digitalWrite(Lane1[0], LOW);
	    digitalWrite(Lane1[2], LOW);
	    digitalWrite(Lane1[1], LOW); 
	    digitalWrite(Lane3[1], LOW);
	    digitalWrite(Lane3[2], LOW);
  	  digitalWrite(Lane3[0], LOW); 
	    digitalWrite(Lane4[1], LOW);
	    digitalWrite(Lane4[2], LOW); 
  	  digitalWrite(Lane4[0], LOW); 
      digitalWrite(Lane2[1], LOW);
	    digitalWrite(Lane2[2], LOW);
  	  digitalWrite(Lane2[0], LOW); 
      break;
   }
}

I have successfully completed my code.. This all because of you @Grumpy_Mike . Thank you so much a lot and lot more :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart:
actually my project is wireless controlled hand-held remote operation for traffic signals in peak hours
I also completed the looping concept also.. I have really completed the program because of you. Building things up slowly .. thank you for your very good clam guidance.

Congratulations, well done for sticking to it. I hope you feel more in control with your code now.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.