irrecv.resume - help!

Before I go insane could someone please be ever so kind and tell me what I need to add into the below coding to make “button2” override the previous “button1” at anytime during the running sequence instead of waiting until the end?

void loop()
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value);
    irrecv.resume(); // Receive the next value

      if (results.value == button1)
    {  
      for (int i = 0; i < loopTimes; ++i) //  WAVE
      {
        Serial.println("Loop 1");
        loop1();
      }
      for (int i = 5; i < loopTimes; ++i) //   OPEN CLOSE FROM CENTER  
      {
        Serial.println("Loop 2");
        loop2();
      }
      for (int i = 5; i < loopTimes; ++i) //   OPEN CLOSE FROM BOTTOM
      {
        Serial.println("Loop 3");
        loop3();
      }
      for (int i = 0; i < loopTimes; ++i) //  STROBE
      {
        Serial.println("Loop 4");
        loop4();

      }
    }
    // How do I make this bit code overide the above code when I press "button2"
    
    if (results.value == button2)
    {  
      for (int i = 0; i < loopTimes; ++i) // WAVE
      {
        Serial.println("Loop 1");
        loop1();
      }
    }
  }
}

You need to check for a new code more often.
A state machine instead of for loops may be in order.

Am I right in thinking that State Machine is a libary ?

There may be a state machine library, I'm not sure.
Break down what you have to do into a series of simple states.
Each iteration, you look to see if a new key code has arrived.
If it has, then your machine enters a new state, otherwise, you continue what you were doing.
Since your code was incomplete, I can't say what those things might be.

This is todays mind numbing code so far…

#include <IRremote.h>
#define button1 16724175
#define button2 16718055
#define button3 16743045
#define button4 16716015
#define button5 16726215
#define button6 16734885
#define button7 16728765
#define button8 16730805
#define RECV_PIN  13

const int loopTimes  = 10;

int Mouth7 = 10;

int Mouth[] = {
  4,5,6,7,8,9};
//  OPEN FROM BOTTOM
int pattern1[] = {
  HIGH,LOW,LOW,LOW,LOW,LOW};
int pattern2[] = {
  HIGH,HIGH,LOW,LOW,LOW,LOW};
int pattern3[] = {
  HIGH,HIGH,HIGH,LOW,LOW,LOW};
int pattern4[] = {
  HIGH,HIGH,HIGH,HIGH,LOW,LOW};
int pattern5[] = {
  HIGH,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern6[] = {
  HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};

// CLOSE FROM TOP
int pattern7[] = {
  HIGH,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern8[] = {
  HIGH,HIGH,HIGH,HIGH,LOW,LOW};
int pattern9[] = {
  HIGH,HIGH,HIGH,LOW,LOW,LOW};
int pattern10[] = {
  HIGH,HIGH,LOW,LOW,LOW,LOW};
int pattern11[] = {
  HIGH,LOW,LOW,LOW,LOW,LOW};
int pattern12[] = {
  LOW,LOW,LOW,LOW,LOW,LOW};

//  OPEN CLOSE FROM CENTER
int pattern13[] = {
  LOW,LOW,LOW,LOW,LOW,LOW};
int pattern14[] = {
  LOW,LOW,HIGH,HIGH,LOW,LOW};
int pattern15[] = {
  LOW,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern16[] = {
  HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};
int pattern17[] = {
  LOW,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern18[] = {
  LOW,LOW,HIGH,HIGH,LOW,LOW};
int pattern19[] = {
  LOW,LOW,LOW,LOW,LOW,LOW}; 

//  WAVE
int pattern20[] = {
  HIGH,LOW,LOW,LOW,LOW,LOW};
int pattern21[] = {
  LOW,HIGH,LOW,LOW,LOW,LOW};
int pattern22[] = {
  LOW,LOW,HIGH,LOW,LOW,LOW};
int pattern23[] = {
  LOW,LOW,LOW,HIGH,LOW,LOW};
int pattern24[] = {
  LOW,LOW,LOW,LOW,HIGH,LOW};
int pattern25[] = {
  LOW,LOW,LOW,LOW,LOW,HIGH};



// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 200;           // interval at which to blink (milliseconds)


IRrecv irrecv(RECV_PIN);
decode_results results;
long lReceived = 0 ;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  for(int i = 0; i < 6; i++)
  {       
    pinMode(Mouth7,OUTPUT); 
    pinMode(Mouth[i],OUTPUT);
  }
}



void loop()
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value);
    irrecv.resume(); // Receive the next value
    {


      if (results.value == button1)

        for (int i = 0; i < loopTimes; ++i) //  WAVE
        {
          Serial.println("Loop 1");
          loop1();

          for (int i = 5; i < loopTimes; ++i) //  OPEN CLOSE FROM CENTER  

            Serial.println("Loop 2");
          loop2();

          for (int i = 5; i < loopTimes; ++i) //  OPEN CLOSE FROM BOTTOM

            Serial.println("Loop 3");
          loop3();

          for (int i = 0; i < loopTimes; ++i) //  STROBE

            Serial.println("Loop 4");
          loop4();
          irrecv.resume(); // Receive the next value
        }



      else if (results.value == button2)
        for (int i = 0; i < loopTimes; ++i) //  WAVE
        {
          Serial.println("Loop 3");
          loop3();
          irrecv.resume(); // Receive the next value
        }
    }
  }
}


void loop1()
{   
  digitalWrite(10, LOW);
  //  WAVE      
  makePattern(Mouth, pattern20, 6);
  makePattern(Mouth, pattern21, 6);
  makePattern(Mouth, pattern22, 6);
  makePattern(Mouth, pattern23, 6);
  makePattern(Mouth, pattern24, 6);
  makePattern(Mouth, pattern25, 6); 

}

void loop2()
{
  digitalWrite(10, LOW);

  //  OPEN CLOSE FROM CENTER           
  makePattern2(Mouth, pattern13, 6);
  makePattern2(Mouth, pattern14, 6);
  makePattern2(Mouth, pattern15, 6);
  makePattern2(Mouth, pattern16, 6);
  makePattern2(Mouth, pattern17, 6);
  makePattern2(Mouth, pattern18, 6);
  makePattern2(Mouth, pattern19, 6);

}

void loop3()
{
  digitalWrite(10, LOW);

  //  OPEN CLOSE FROM BOTTOM
  makePattern2(Mouth, pattern12, 6);
  makePattern2(Mouth, pattern11, 6);
  makePattern2(Mouth, pattern10, 6);
  makePattern2(Mouth, pattern9, 6);
  makePattern2(Mouth, pattern8, 6);
  makePattern2(Mouth, pattern7, 6);
  makePattern2(Mouth, pattern6, 6);
  makePattern2(Mouth, pattern5, 6);
  makePattern2(Mouth, pattern4, 6);
  makePattern2(Mouth, pattern3, 6);
  makePattern2(Mouth, pattern2, 6);
  makePattern2(Mouth, pattern1, 6);

}

void loop4()
{
  //  STROBE
  digitalWrite(10, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);  
  delay(100);
  digitalWrite(10, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  delay(100);
}



/*
 * makePattern - this function has three parameters:
 *   leds[]-an array of output pins connected to LEDs
 *   pattern[]-an array containing HIGH or LOW to indicate whether an LED is on or off
 *   num-the number of LEDs
 */
void makePattern(int leds[], int pattern[], int num)
{
  int delayTime = 100;
  for(int i = 0; i < num; i++)
  {
    digitalWrite(leds[i], pattern[i]); 
  }
  delay(delayTime);
}

void makePattern2(int leds[], int pattern[], int num)
{
  int delayTime = 50;
  for(int i = 0; i < num; i++)
  {
    digitalWrite(leds[i], pattern[i]); 
  }
  delay(delayTime);
}

Was there a question?

This is todays mind numbing code so far...

  delay(100);
  delay(100);
  delay(delayTime);
  delay(delayTime);

You got that right...

Ha not since the first one....

With you saying.....

Since your code was incomplete, I can't say what those things might be.

......Thought I'd post the full code, just encase you wanted to attempt to make sense of it.

You got that right...

Paul - What do you mean?

What do you mean?

Those delay()s are often executed many times before you read another remote button press. The use of delay() and responsiveness (which appears to be why you posted) are not compatible.

So if I were to remove those delays the remote button press will work ?

So if I were to remove those delays the remote button press will work ?

The time between when the Arduino first considers whether a button on the remote was pressed and the next time it considers whether a button on the remote was pressed would be greatly reduced. Whether that is enough to transition from "doesn't work" to "works" depends on your definitions of each term. I would guess, though, that yes, it would work. The problem, of course, is that those delay()s serve some purpose, and just deleting them is not going to result in the rest of the code still working the same way it does now.

You have a major re-write ahead of you to get rid of the delay() calls.

You have a major re-write ahead of you to get rid of the delay() calls.

I feel like I've done several major re-writes already. All part of the learning curve I suppose!

The finished product (not the coding) is so close to looking spot on. If I were to get that remote button working I'l be away!!

My head is starting to hurt from hitting it off the wall ! XD

My head is starting to hurt from hitting it off the wall !

So, stop doing that. 8)

Learn how to use millis() and states to determine if it is time to do something (else). Update the last time something happened, and the state (which defines what to do next).

You will thoroughly appreciate this new knowledge on future projects, time critical or not.

HI EVERYONE…
I HAVE THIS SKETCH…

#include <IRremote.h>

int RECV_PIN = 11;
int led = 13;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if(irValue == 16736925){
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
irrecv.resume(); // Receive the next value
}
delay(100);
}

BUT EACH ALTERATION OF THE LOOP, I HAVE TO PRESS THE BUTTON ON THE REMOTE BEFORE THE LIGHT BLINK AGAIN…

IS THERE A WAY THAT I CAN ADD TIMEOUT TO THE irrecv.resume(); SUCH THAT, IT LISTEN FOR SIGNAL FROM THE REMOTE IN A SHORT TIME, AND IF NOT, IT GO BACK TO THE digitalWrite(); AND TURN THE LED ON AND OFF???

I NEED HELP ON THIS

IS THERE A WAY THAT I CAN ADD TIMEOUT TO THE irrecv.resume(); SUCH THAT, IT LISTEN FOR SIGNAL FROM THE REMOTE IN A SHORT TIME, AND IF NOT, IT GO BACK TO THE digitalWrite(); AND TURN THE LED ON AND OFF???

There is no need to shout.

Look at what the code does:

void loop()
{
  if (irrecv.decode(&results)) 
  {
    Serial.println(results.value, HEX);
    // Do something with the value
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

First, why is there a delay there?
Second, if you want the value read from the IR used over and over, why is the "Do something with the value" part of the code in the "if we got a new value from the IR" block?

Put that code in a function. Call that function. Move the call around until it happens when it should.