My Program confuses me so much.

So I am trying to make my room made auto in a way. I am trying to hook an IR remote to IR sensor. The problem isn't in the wiring or remote. So here is my code:

#include <IRremote.h>
#include <FastLED.h>
#define NUM_LEDS 60 
#define DATA_PIN 7  
#define COLOR_ORDER GRB
#define LED_TYPE WS2812B
int og = 0;
int ledspeed=1;
uint8_t max_bright = 64; 
CRGB leds[NUM_LEDS];
int IRpin = 11;  
int LED = 13;    
IRrecv irrecv(IRpin);
decode_results results;

boolean LEDon = true; // initializing LEDon as true

void setup()
{
  delay(100);

  irrecv.enableIRIn(); // Start the receiver
  FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  FastLED.setBrightness(max_bright);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() 
{
  if (irrecv.decode(&results)) 
    {
       Serial.println(results.value, DEC); 
      irrecv.resume();   
    }
  
  switch(results.value)
 {

  case 16:
  {
  digitalWrite(LED,HIGH);  
  }
  break;
  
  case 2064:
  {
    digitalWrite(LED,LOW);
  }
  break;
  default:
fill_rainbow ( leds,NUM_LEDS,og,10); // These 3 lines make my led strip work
FastLED.show();//These 3 lines make my led strip work
og++; //These 3 lines make my led strip work
   break;
  }
 
}

Now what this does is turn on an led off and on when I press the keys 1 and 2 on my remote. The ir number for 1 is 16, and The ir number for 2 is 2064, obviously. The code works perfectly without the 3 lines "These 3 lines make my led strip work", it lets me turn the led on and off. But when those 3 lines are put into the code in any position or order the ir sensor just falls flat. So instead of giving me 16 when I press '1' it gives me a 7 digit number that is completely random. What do I do to fix this, thanks for reading. Please help!

I'm pretty new to this by the way. I tried to go to the IR libraries for examples but when I posted the example it won't even upload. Those examples seem to complicate it much more than it has to be I think

This is pissing me off. I keep on moving those 3 lines to make it work but it won't. I figured out which lines messes it up. Its "FastLED.show();" if you remove this the serial print in will show the right numbers for each button. But when I put it in default, the first line after void loop, the last line when void loop ends, or outside of the last break In the switch function it will totally break IR print in. It just spews random numbers each time I press a button. But if I put that in-between a case and a break, not a default for some reason, then the IR read out is correct. I DO NOT UNDERSTAND.

You are doing that case statement every time round the loop that is irrespective of whether you have received an IR command or not. So you are spamming the LEDs and so turning off the interrupts all the time. This does not let the IR have a look in. Look to the positioning of those braces { } and only do stuff when you receive something.

Grumpy_Mike:
So you are spamming the LEDs and so turning off the interrupts all the time. This does not let the IR have a look in. Look to the positioning of those braces { } and only do stuff when you receive something.

I don't understand what is spamming it? The Led strip 3 code lines turn the strip on and the strip works. But I don't understand your explanation. Could you be more specific please? Thank you.

case 16:
    {
    fill_rainbow ( leds,NUM_LEDS,og,10); // These 3 lines make my led strip work
    og++;
    FastLED.show();//These 3 lines make my led strip work
    digitalWrite(LED,HIGH);  
    rainbowX=true;
  }
  break;
  
  case 2064:
    {
    rainbowX=false;
    fill_solid(leds, NUM_LEDS,CRGB(0,0,0));  
    FastLED.show();
    digitalWrite(LED,LOW);
  }
  break;

Okay that is the revised code. I see what you meant. But there is still an issue. It gives me the write number but also a repeat code and a random number. For some reason the order of the 3 numbers will change randomly. Like if I press remote '1' I get 16, Random number, 4294967295. This makes the case to only activate once. This is problematic. It won't allow the Led strip to do it's beautiful flowing effect (og++;). So I tried to fix this with making a variable rainbowX. This was just going to turn on and off the led strip in another switch function. But when Inserted the led strip code into the other switch command (rainbow X), it ruined my IR output again. This is so stupid. Why can't I run the FastLED.show(); anywhere but the case. It totally limits my ability to do anything cool. If I can't run that any where then how can I plan on running more than one function at once.

When you post code you think you have fixed post all of it. That last post of code was not on the area I was pointing at. Spamming in this context means unnecessary writing to the LEDs. When you write to the LEDs the code in the library turns off the interrupts off, that stops the IR code from working.

Read through each line of that loop. You read to see if their has been an IR result, then irrespective of whether their has been one or not you go through the switch statement.
Change the braces so that you ONLY go through the switch structure IF their has been a result.

Once again thanks for the help.
...

Grumpy_Mike:
Spamming in this context means unnecessary writing to the LEDs.

I've made my device operate with your advice now. but you select the settings of the Ledstrip on the remote then press a button. Once the button is pressed IR signals are basically jammed. Press the button again and the led strip will stay in its last position and IR signals are unjammed. The thing were the case would only be preformed when the sensor receives a IR signal (What I think you told me to do) only halfway works. It works perfectly if you just want to change the color of the led once like lets say

if (irrecv.decode(&results)) 
    {
       Serial.println(results.value, DEC); 
      irrecv.resume();   
 
switch(results.value)
    {

  case 16:
    {
          fill_solid(leds,NUM_LEDS, CRGB(255,0,0));
          FastLED.show();//These 3 lines make my led strip work
  }
  break;
    case 2064:
    {
           fill_solid(leds,NUM_LEDS, CRGB(0,0,255));
           FastLED.show();//These 3 lines make my led strip work
  }
}
}

But the problem occurs when I need a color changing led.

reading = digitalRead(button1);
    if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH){
      state = LOW;
      power = false;
    }
    else{
      state = HIGH;
      power = true;
    time = millis();
    }
  }

  digitalWrite(LED, state);

  previous = reading;
  

  
  if (irrecv.decode(&results)) 
  
    {
       Serial.println(results.value, DEC); 
      irrecv.resume();   
    
    
  
switch(results.value)
    {

  case 16:
    {
    rainbowX=true;
  }
  break;
    case 2064:
    {
    rainbowX=false;
  }
  break;
    case 2704:
    {
    }
    case 624:
    {
    ledstrip=false;  
    }
  break;
    case 14318:
    {
    ledstrip=true;
    }
  break;
    case 3088:
    {
      
    }
  }
    }
og++;
if(power==true){
switch  
  
  
  
  
  if(ledstrip==true&&rainbowX==true){
    fill_rainbow ( leds,NUM_LEDS,og,10); 
          FastLED.show();//These 3 lines make my led strip work

   }
  else if(ledstrip==true&&rainbowX==false){
    fill_solid(leds,NUM_LEDS, CRGB(0,0,255));
          FastLED.show();//These 3 lines make my led strip work

    }
  else if(ledstrip==false){
    fill_solid(leds, NUM_LEDS,CRGB(0,0,0)); 
          FastLED.show();//These 3 lines make my led strip work

    }
}

Ideally, I'd like to use the remote and not be forced to used a button and have a moving led operating at the same time.
You have to send FastLED.show(); constantly in the loop for a moving led strip but it seems automatically jam a IR sensor. I don't see any possible way around this. And after I lay the ground works and get this first moving led done I plan on making a sound sensitive option. What's the point of using the remote if I have to use the button anyways?

It is hard to comment properly when you don't post ALL the code each time.

You have to send FastLED.show(); constantly in the loop for a moving led strip but it seems automatically jam a IR sensor. I don't see any possible way around this.

That is the problem with trying to use the two things at once. You might be able to get away with it because an IR remote sends the code several times so as long as you keep calling the irrecv.decode regularly and updating the LEDs in a state machine style you might get away with it.

What's the point of using the remote if I have to use the button anyways?

For the way you are tackling things at the moment then none. But this is an important lesson in design, you can not just throw things together without understanding what they are and expect them to work, although they will sometimes. It is part of the penalty of using the LEGO building block approach currently encouraged by this, and other platforms.

You could always call in some hardware assistance, like an IR receiver chip.

However if you can't get things to work with proper scheduling then this is might one of those rare occasions where using two Arduinos might be a good idea. Have one handle the IR, you might use something like an ATtiny85, and communicate with the other when the IR code is received.