Receiving Different IR Codes From Same Remote/Button

akeom:
Hi, same problem here. Following experiment:

  • I commented out nearly all of my main loop
  • after that, I could receive the right button-pressed codes
  • uncommented main loop ->> same problem again.

I am observing the same behavior. After a few hours of debugging, I've found that I'm able to retain the majority of my original main loop() commands, provided I insert a delay() call of at least ~200ms. With this, I don't see perfect interpretation of the IR signals, but at least half of them are received correctly. I'm wondering if it's a timing issue, where if the IR signal is received while the loop() function is processing other data, it somehow jumbles the result. This makes me curious if it is a performance issue or whether the IRremote library could be modified to halt other processing as soon as it starts receiving a signal. I'm not an expert with Arduino, but I would have thought an interrupt-driven event would do this anyway.

Does anyone have any suggestions?

As background, what I'm trying to accomplish is control of an LED strip using the FastLED library, then altering the LED sequence with an IR remote. So far all I've implemented is brightness control, but if I can get this working, there's a whole slew of features I'd like to add.

For reference, here's my code:

#include "IRremote.h"
#include <FastLED.h>

#define LED_PIN     6
#define NUM_LEDS    150
#define LED_TYPE    WS2812B
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

// set up global variable for tracking LED brightness, initially set to half-power
uint8_t brightness = 128;
#define BRIGHTNESS_INCR 16

#define IR_PIN 11  // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(IR_PIN);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
{
 // describing Remote IR codes 
 switch(results.value)
 {
   case 0xFFA25D: Serial.println("POWER"); break;
   case 0xFFE21D: Serial.println("FUNC/STOP"); break;
   case 0xFF629D: Serial.println("VOL+"); 
     if (255 - brightness < BRIGHTNESS_INCR) {
       brightness = 255;
     } else {
       brightness += BRIGHTNESS_INCR;
     }
     Serial.println(brightness);
     break;
   case 0xFF22DD: Serial.println("FAST BACK");    break;
   case 0xFF02FD: Serial.println("PAUSE");    break;
   case 0xFFC23D: Serial.println("FAST FORWARD");   break;
   case 0xFFE01F: Serial.println("DOWN");    break;
   case 0xFFA857: Serial.println("VOL-");
     if (brightness < BRIGHTNESS_INCR) {
       brightness = 0;
     } else {
       brightness -= BRIGHTNESS_INCR;
     }
     Serial.println(brightness);
     break;
   case 0xFF906F: Serial.println("UP");    break;
   case 0xFF9867: Serial.println("EQ");    break;
   case 0xFFB04F: Serial.println("ST/REPT");    break;
   case 0xFF6897: Serial.println("0");    break;
   case 0xFF30CF: Serial.println("1");    break;
   case 0xFF18E7: Serial.println("2");    break;
   case 0xFF7A85: Serial.println("3");    break;
   case 0xFF10EF: Serial.println("4");    break;
   case 0xFF38C7: Serial.println("5");    break;
   case 0xFF5AA5: Serial.println("6");    break;
   case 0xFF42BD: Serial.println("7");    break;
   case 0xFF4AB5: Serial.println("8");    break;
   case 0xFF52AD: Serial.println("9");    break;
   case 0xFFFFFFFF: Serial.println(" REPEAT");break;  
   default: 
     Serial.println(" other button  ");
     
   }// End Case
   Serial.println(results.value, HEX);

 delay(200); // Do not get immediate repeat
} //END translateIR

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
 // LED Setup
 delay( 3000 ); // power-up safety delay
 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
 FastLED.setBrightness( brightness );
 currentPalette = RainbowColors_p;
 currentBlending = LINEARBLEND;

 // IR Setup
 Serial.begin(9600);
 Serial.println("IR Receiver Button Decode"); 
 irrecv.enableIRIn(); // Start the receiver
}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
 if (irrecv.decode(&results)) { // have we received an IR signal?
   translateIR(); 
   irrecv.resume(); // receive the next value
 }
 delay(200);
  
 static uint8_t startIndex = 0;
 startIndex = startIndex + 1; /* motion speed */
 FillLEDsFromPaletteColors( startIndex);
 FastLED.show();
 FastLED.delay(1000 / UPDATES_PER_SECOND);
}/* --(end main loop )-- */

// Function to actually set LED colors
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
   // uint8_t brightness = 255;
   
   for( int i = 0; i < NUM_LEDS; i++) {
       leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
       colorIndex += 3;
   }
}