Arduino Switching Between Loops IR Remote I've been working on an LED strip project. However, I've come to a stand still at the moment. Within the program I am wanting to assign different lighting effects to each button on my IR remote. I am wanting the program to work on the basis that each lighting effect will run, until another button is pressed, to start another effect.

Currently with my code I have made it so each effect will run, once, when the corresponding button on the IR remote is pressed.

I am fairly new to C++ / Arduino but from my understanding I need to have a variable which would hold the current value of the IR remote. I am unsure on how to actually implement this. I will post my code below and if anyone could give me tips or even amendments to my code it would be to a great help.

Thank you in advanced.


#include "IRremote.h"
#include &lt;Adafruit_NeoPixel.h&gt;
#ifdef __AVR__
#include &lt;avr/power.h&gt;
#endif
#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800);

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'
int Remote = 0;

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes 

{
  switch(results.value)
  {
  case 0xFFA25D: Serial.println("POWER"); 
  ArrowRight(strip.Color(25, 0, 0), 100); //Red
  ArrowRight(strip.Color(0, 0, 25), 100); //Blue
  break;

  case 0xFFE21D: Serial.println("FUNC/STOP"); 
  ArrowLeft(strip.Color(25, 0, 0), 100); // Red
  ArrowLeft(strip.Color(0, 0, 25), 100); // Blue
  break;


  default: 
  Serial.println(" other button   ");

  }// End Case

  delay(0); // Do not get immediate repeat


} //END translateIR
void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn(); // Start the receiver
  strip.begin();
  strip.show();
  Remote = 0;

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&amp;results)) // have we received an IR signal?

  {
    translateIR(); 
    irrecv.resume(); // receive the next value
  }  
}/* --(end main loop )-- */

void ArrowRight(uint32_t c, uint8_t wait) {
  for (int j = 0; j &lt; 1; j++) { // The j&lt;# determines how many cycles
    for (uint16_t i = strip.numPixels()/2; i &lt; strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(50);
    }
    for (uint16_t i = 0; i &lt; strip.numPixels(); i++) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(50);
  }
}

void ArrowLeft(uint32_t c, uint8_t wait) {
  for (int j = 0; j &lt; 1; j++) { // The j&lt;# determines how many cycles
    for (uint16_t i = strip.numPixels()/2-1; i + 1 &gt; 0 ; i--) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(50);
    }
    for (uint16_t i = strip.numPixels(); i + 1 &gt; 0 ; i--) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(50);
  }
}
delay(0) apparently[*] acts like delay(2^32) or about 10^10 milliseconds. That may not be what you had in mind ... :) 

Try reducing the delay to 1 or use delayMicroseconds() to get something shorter. That should at least get you some repeatable results.

(10^10 mSec is ~ 16.5 weeks, for those without a calculator handy).

[*]  I didn't read the code, nor wait for the call to expire. I tried it and saw that the Uno froze. I'm guessing a zero-argument to delay() isn't rejected but just gets decremented as usual, until it hits zero.