End looping with IR signal

Hi everyone, I'm not new to programming but I am new to programming hardware and new to Arduino, having only had it for a few days.

I have an application that I'm working on where I turn on or off LEDs with an IR remote. In one scenario the LEDs should blink on and off until another command is received from the IR remote.

I have the following code but it doesn't recognize when another IR signal is received.

#include <IRremote.h> // use the library for IR

// constants won't change. Used here to set pin numbers:
const int redLEDPin = 2;      // the number of the LED pin
const int whiteLEDPin = 3;      // the number of the LED pin
const int irRemotePin = 11;      // pin 1 of IR receiver to Arduino digital pin 11

IRrecv irrecv(irRemotePin);      // create instance of 'irrecv'
decode_results results;

// Variables will change:
int redLEDState = LOW;      // ledState used to set the LED
int whiteLEDState = LOW;      // ledState used to set the LED
int lightsLEDState = LOW;	// ledState used to set the LED

//============================================================================
// Variables will change:
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 500;           // interval at which to blink (milliseconds)
//============================================================================

void translateIR() // takes action based on IR code received
{
  long results_value = results.value;
  switch(results_value)
  {
    case 0xFFC23D:  
      LightsOnOff();
      break;
  }
}


void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(redLEDPin, OUTPUT);
  pinMode(whiteLEDPin, OUTPUT);
}

void loop()
{
  // test for IR reception
  irReceive();
}

int irReceive()
{
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
    translateIR();
    for (int z=0; z<2; z++) // ignore 2nd and 3rd signal repeat
    {
      irrecv.resume(); // receive the next value
    }
  }
}

void LightsOnOff()
{
  if (lightsLEDState == LOW)
  {
    lightsLEDState = HIGH;
  }
  else
  {
    lightsLEDState = LOW;
  }
  
  while (lightsLEDState == HIGH)
  {
    lightsLoop();
  }
}

void lightsLoop()
{
  Serial.println("running lights");
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval)
  {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    digitalWrite(redLEDPin, HIGH);
    digitalWrite(whiteLEDPin, HIGH);
    delay(500);
    digitalWrite(redLEDPin, LOW);
    digitalWrite(whiteLEDPin, LOW);
    delay(500);
  }
}

I know there are easier ways to simply blink a LED but I have more going on inside of the sections that are lighting the LEDs. I have only pasted in the relevant compilable portions of the code so that any responses could be about the actual problem.

What I need help with is how to call the irReceive() function again from inside the loop without stopping the loop. Everything I have tried has resulted in the loop stopping or never seeing the second button press.

Basically the functionality should be: press remote button once the loop starts and runs until the same button is pressed again.

Thanks in advance,
Jay

You call this, but you never change lightsLEDState so it's going to loop forever

while (lightsLEDState == HIGH)
  {
    lightsLoop();
  }

Yes, obviously. Thank you for taking the time to respond but I'm not that new to programming. :wink:

What I intended with the code pasted above is to give a working example once the button has been pressed once.

What I need help with is the second portion, detecting the second button press so that the loop will be ended but only if it is the correct button.

If I simply put a call to irReceive() inside of the loop it will cause the loop to end regardless of if a button was actually pressed.

Thank you,
Jay

Please take a look at this tutorial http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
This should help you get your code running how you need it.
If you still need further instructions after reading through the tutorial, I will try to help.

Thank you for taking the time to respond but I'm not that new to programming.

That is exactly why code snippets are not advised. The code you snipped to get what you posted made you look like a

Moderator edit: unwarranted personal insult removed. Keep it civil, please.AWOL

Post all of your code.

@PaulS: did you read the original post fully?
If you had, you would have noticed a complete sketch.

@AWOL, the original poster said he took out lots of code to make it easier to read.
From original post

I know there are easier ways to simply blink a LED but I have more going on inside of the sections that are lighting the LEDs. I have only pasted in the relevant compilable portions of the code so that any responses could be about the actual problem.

But it is a complete code, whittled down to the just problem, just like we ask people to try to do.

But it is a complete code, whittled down to the just problem, just like we ask people to try to do.

It is complete, and it does compile. It does contain errors (at least one) that were pointed out as being significant. Rather than admit that the error existed, and needed to be fixed, OP got defensive.

If OP wants help with some code, the code needs to either be complete and error free, and still demonstrate the problem, or it needs to be the actual code that OP is having a problem with.

In that code, once the function gets called, there is no way for it ever to end, which is the problem that OP is complaining about.