FastLED and IR - IR stops working after a while

Hi,

I am trying to solve a problem with my code. So it works all well But at one point IR stops reacting. Serial doesnt print anything but the patterns continue to animate. IR reciever LED also blinks along with the remote. After restart it works again. I cannot figure it out for the whole day. Would someone be willing to look at my code?

//import the necessary libraries
#include "FastLED.h"
#include "IRremote.h"

//define some variables

#define DATA_PIN  3
#define CLK_PIN   4
#define RECV_PIN  9
#define LED_TYPE     APA102
#define COLOR_ORDER BGR
#define NUM_LEDS    34
#define BRIGHTNESS  204
#define FRAMES_PER_SECOND 30 
CRGB leds[NUM_LEDS];
CRGB endclr;
CRGB midclr;
int check = 0;
int b = 204;

uint32_t Previous = 0; 
int mode;


//set up IR receiver information
IRrecv irrecv(RECV_PIN);
decode_results results;

//<————————————————————————————SETUP————————————————————————————>
void setup()
{
//begin serial communication
  Serial.begin(9600);
//sanity delay
  delay(3000); 
//start the receiver
  irrecv.enableIRIn(); 
  
//set up LED strip information
FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);

}

//<————————————————————————————PATTERN SETUP————————————————————————————>
// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { white, green, red, confettiWhite, confettiGreen, confettiRed, BreatheWhite, BreatheGreen, BreatheRed, Black};

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current

uint8_t gHue = 0; // rotating "base color" used by many of the patterns


//<—————————————————————————LOOP———————————————————————————————>
void loop() {

// Delay 
FastLED.delay(1000/FRAMES_PER_SECOND);
FastLED.setBrightness(b);


// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();



// Decode values from IR reciever and clean up duplicates  
if (irrecv.decode(&results)) {
  if (results.value==0xFFFFFFFF) { 
      results.value=Previous;
      }
  if (results.value==0) { 
      results.value=Previous;
      }
   if (results.value!=Previous) 
      { 
      Serial.println (results.value, HEX); //display HEX results 
      }
      irrecv.resume(); // Receive the next value     
}
Previous=results.value;



//<——————————————————FX CONTROL—————————————————————————>




EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
//EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically




 
//<——————————————————BUTTON FUNCTIONS—————————————————————————>

if (results.value == 0xFFA25D){ // 1 - White
gCurrentPatternNumber = 0;
results.value=0;
}

if (results.value == 0xFF629D){ // 2 - Green
gCurrentPatternNumber = 1;
results.value=0;
}

if (results.value == 0xFFE21D){ // 3 - Red
gCurrentPatternNumber = 2;
results.value=0;
}

if (results.value == 0xFF22DD){ // 4
 gCurrentPatternNumber = 3; 
 results.value=0;
} 

if (results.value == 0xFF02FD){ gCurrentPatternNumber = 4; results.value=0;} //5
if (results.value == 0xFFC23D){ gCurrentPatternNumber = 5; results.value=0;} //6
if (results.value == 0xFFE01F){ gCurrentPatternNumber = 6; results.value=0;} //7
if (results.value == 0xFFA857){ gCurrentPatternNumber = 7; results.value=0;} //8
if (results.value == 0xFF906F){ gCurrentPatternNumber = 8; results.value=0;} //9


if (results.value == 0xFF9867){ //0
gCurrentPatternNumber = 9;
}

if (results.value == 0xFF10EF){b = b-25;  if (b<=4) {b=4;} results.value=0;} //left

if (results.value == 0xFF5AA5){b = b+25; if (b>=255) {b=255;} results.value=0;} //right

/*
if (results.value == 0xFFB04F){ // Hashtag - Breathe
gCurrentPatternNumber = 11;
}


if (results.value == 0xFF6897){ // * - sparkle
gCurrentPatternNumber = 10;
}
*/
/*
if (results.value == 0xFF22DD){} //4
if (results.value == 0xFF02FD){} //5
if (results.value == 0xFFC23D){} //6
if (results.value == 0xFFE01F){} //7
if (results.value == 0xFFA857){} //8
if (results.value == 0xFF906F){} //9



if (results.value == 0xFF9867){} //0

if (results.value == 0xFF10EF){} //left
if (results.value == 0xFF5AA5){} //right
if (results.value == 0xFF18E7){} //up
if (results.value == 0xFF4AB5){} //down
if (results.value == 0xFF38C7){} //ok
*/

//<——————————————————WRTITE TO LED—————————————————————————>
FastLED.show(); 
//Serial.println (b);
}


//<——————————————————PATTERN ARRAY—————————————————————————>
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))


void white() 
{
fill_solid(leds,NUM_LEDS,CRGB::White);
}

void green() 
{
fill_solid(leds,NUM_LEDS,CRGB::Green);
}

void red() 
{
fill_solid(leds,NUM_LEDS,CRGB::Red);  
}

void Black() 
{
fill_solid(leds,NUM_LEDS,CRGB::Black);  
}


void BreatheWhite() 
{     
fill_solid(leds,NUM_LEDS,CRGB::White);
//FastLED.setBrightness( beatsin8(4,50,255));
}

void BreatheRed() 
{     
fill_solid(leds,NUM_LEDS,CRGB::Red);  
//FastLED.setBrightness( beatsin8(4,50,255));
}

void BreatheGreen() 
{ 
fill_solid(leds,NUM_LEDS,CRGB::Green);    
//FastLED.setBrightness( beatsin8(4,50,255));
}

void confettiWhite() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV(255, 0, 255);
}

void confettiGreen() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = random16(NUM_LEDS);
  leds[pos] = CRGB::Green;
}

void confettiRed() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = random16(NUM_LEDS);
  leds[pos] = CRGB::Red;
}

void sinelonWhite()
{
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = beatsin16( 7, 0, NUM_LEDS-1 );
  leds[pos] = CRGB::White;
}

It sounds like you are powering with the Arduino and it is not capable of driving your complete load. I assume the regulator is getting hot and starting to shut down. Post a schematic, not a frizzy thing, showing all power, ground, interconnections and power sources.

IRremote and FastLED are not compatible libraries. IRremote relies heavily on interrupts and FastLED turns them off, although for the LED chip you are using only momentarily when calling show()
But if you use FastLED.delay(1000/FRAMES_PER_SECOND);You will be calling show() repeatedly until the delayTime has elapsed. In my opinion FastLED.delay() is the worst idea ever,(look up the function in the library just to check) why would you anyway want to send a signal to LED's if there has been no change to the buffer. Anyway if you change it todelay(1000/FRAMES_PER_SECOND);You will probably have a system which is reliably enough.

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