user42506: So I am using Arduino to control RGB Strip light, the analogueWrite(Pin,Value); Works with the prebuilt AnalogueWriteMega example - on pins 8, 9, and 10.
When I move this into my program, Pin 8 still works but pins 9 and 10 don't work.
Anywhere I write analogueWrite() it only works if the value is 255

Green is pin 8
Red is pin 9
Blue is pin 10

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

#include <LiquidCrystal.h>
// encoder
int val;
int encoder0PinS = 29;
int encoder0PinA = 31;
int encoder0PinB = 33;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
int MenuPos;
int SubPos;
bool Selected = false;
int Reader = LOW;

// lcd
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//pot
int ASensePin = A0;
double ASenseValue = 0;
double AFixedValue = 0;
int AFixOut = 0;

//randoms
int ranPin;
int ranVal;

//IR

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

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



void translateIR() { // takes action based on IR code received

  // describing Remote IR codes
  switch (results.value)
  {


    case 16195807:
      Serial.println("Red, 0, 255, 0");
      analogWrite(8, 0);
      analogWrite(9, 255);    < ------ works
      analogWrite(10, 0);
      break;

    case 16197847:
      Serial.println("Yellow, 255, 255, 0");
      analogWrite(8, 100);      < ----don't work
      delay(50);
      analogWrite(9, 100);       <----don't work
      delay(50);
      analogWrite(10, 0);
      break;


    case 16228447:
      Serial.println("green, 255 , 0, 0");
      analogWrite(8, 255);
      analogWrite(9, 0);
      analogWrite(10, 0);
      break;

    case 16230487:
      Serial.println("turquois, 0, 255, 255");
      analogWrite(8, 0);
      delay(50);
      analogWrite(9, 100);
      delay(50);
      analogWrite(10, 100);
      delay(50);
      break;

    case 16212127:
      Serial.println("blue, 0, 0, 255");
      analogWrite(8, 0);
      analogWrite(9, 0);
      analogWrite(10, 255);
      break;

    case 16214167:
      Serial.println("Purple, 255, 0, 255");
      analogWrite(8, 100);
      delay(50);
      analogWrite(9, 0);
      delay(50);
      analogWrite(10, 100);
      delay(50);
      break;

    case 16244767:
      Serial.println("White, 255, 255, 255");
      analogWrite(8, 255);
      analogWrite(9, 255);
      analogWrite(10, 255);
      break;

    default:
      Serial.println(results.value);
  }// End Case

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



void setup() {
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);
  pinMode (encoder0PinS, INPUT);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);

  lcd.begin(16, 2);
  lcd.print("      Start     ");

  Serial.begin (9600);
}

void loop() {
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
  }
  encoder0PinALast = n;
  if (encoder0Pos == 4) {
    encoder0Pos = 0;
  }
  if (encoder0Pos == -1) {
    encoder0Pos = 3;
  }

  MenuPos = encoder0Pos;

  Reader = digitalRead(encoder0PinS);
  // Serial.println(Reader);

  if (digitalRead(encoder0PinS) == LOW) {
    while (digitalRead(encoder0PinS) == LOW) {}
    Selected = true;
  }

  Serial.println("MenuLoop");
  switch (MenuPos) {
    case 0:
      lcd.setCursor(0, 0);
      lcd.print("     Random    ");
      while (Selected == true) {
        ranPin = random(8, 10);
        ranVal = random(0, 255);
        analogWrite(ranPin, ranVal);

        if (digitalRead(encoder0PinS) == LOW) {
          while (digitalRead(encoder0PinS) == LOW) {}
          Selected = false;
        }
      }
      break;

    case 1:
      lcd.setCursor(0, 0);
      lcd.print("       IR      ");
      Serial.println("IR Receiver Button Decode");
      irrecv.enableIRIn(); // Start the receiver

      while (Selected == true) {
        if (irrecv.decode(&results)) // have we received an IR signal?
        {
          translateIR();
          irrecv.resume(); // receive the next value
          lcd.setCursor(0, 1);
          lcd.print("               ");
          lcd.setCursor(0, 1);
          lcd.print(results.value);
        }
        if (digitalRead(encoder0PinS) == LOW) {
          while (digitalRead(encoder0PinS) == LOW) {}
          Selected = false;
        }
      }

      break;

    case 2:
      lcd.setCursor(0, 0);
      lcd.print("      Temp     ");
      break;

    case 3:
      lcd.setCursor(0, 0);
      lcd.print("      Pot      ");

      while (Selected == true) {


Not working
        for (int thisPin = 8; thisPin <= 10; thisPin++) {
          // fade the LED on thisPin from off to brightest:
          for (int brightness = 0; brightness < 255; brightness++) {
            analogWrite(thisPin, brightness);
            delay(2);
          }
          // fade the LED on thisPin from brightest to off:
          for (int brightness = 255; brightness >= 0; brightness--) {
            analogWrite(thisPin, brightness);
            delay(2);
          }
          // pause between LEDs:
          delay(100);
        }


        if (digitalRead(encoder0PinS) == LOW) {
          while (digitalRead(encoder0PinS) == LOW) {}
          Selected = false;
        }
      }
      break;
  }
}


user4143: The problem has nothing to do with your switch code. It's all to do with what you are trying to do, and peripherals conflicting.
Simply put: both PWM on pins 9 & 10, and the infrared library, require exclusive use of Timer 2. 
Only one can use it. Either the infrared library, or PWM on those two pins, but not both.
You can modify the IR library to use a different timer instead of Timer 2 - for instance, you can set it to use Timer 1 which will remove your ability to use pins 11 and 12 as PWM.
This is the bit of code that you would need to find and modify on your system to change timers.  This page shows you which timers are used for PWM on which pins.

42506: <p>So I am using Arduino to control RGB Strip light, the <code>analogueWrite(Pin,Value);</code> Works with the prebuilt AnalogueWriteMega example - on pins 8, 9, and 10.</p>

<p>When I move this into my program, Pin 8 still works but pins 9 and 10 don't work.</p>

<p>Anywhere I write <code>analogueWrite()</code> it only works if the value is 255</p>

<ul>
<li>Green is pin 8</li>
<li>Red is pin 9</li>
<li>Blue is pin 10</li>
</ul>



<pre class="lang-cpp prettyprint-override"><code>#include &lt;boarddefs.h&gt;
#include &lt;IRremote.h&gt;
#include &lt;IRremoteInt.h&gt;
#include &lt;ir_Lego_PF_BitStreamEncoder.h&gt;

#include &lt;LiquidCrystal.h&gt;
// encoder
int val;
int encoder0PinS = 29;
int encoder0PinA = 31;
int encoder0PinB = 33;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
int MenuPos;
int SubPos;
bool Selected = false;
int Reader = LOW;

// lcd
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//pot
int ASensePin = A0;
double ASenseValue = 0;
double AFixedValue = 0;
int AFixOut = 0;

//randoms
int ranPin;
int ranVal;

//IR

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

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



void translateIR() { // takes action based on IR code received

  // describing Remote IR codes
  switch (results.value)
  {
</code></pre>

<hr>

<pre class="lang-cpp prettyprint-override"><code>    case 16195807:
      Serial.println("Red, 0, 255, 0");
      analogWrite(8, 0);
      analogWrite(9, 255);    &lt; ------ works
      analogWrite(10, 0);
      break;

    case 16197847:
      Serial.println("Yellow, 255, 255, 0");
      analogWrite(8, 100);      &lt; ----don't work
      delay(50);
      analogWrite(9, 100);       &lt;----don't work
      delay(50);
      analogWrite(10, 0);
      break;
</code></pre>

<hr>

<pre class="lang-cpp prettyprint-override"><code>    case 16228447:
      Serial.println("green, 255 , 0, 0");
      analogWrite(8, 255);
      analogWrite(9, 0);
      analogWrite(10, 0);
      break;

    case 16230487:
      Serial.println("turquois, 0, 255, 255");
      analogWrite(8, 0);
      delay(50);
      analogWrite(9, 100);
      delay(50);
      analogWrite(10, 100);
      delay(50);
      break;

    case 16212127:
      Serial.println("blue, 0, 0, 255");
      analogWrite(8, 0);
      analogWrite(9, 0);
      analogWrite(10, 255);
      break;

    case 16214167:
      Serial.println("Purple, 255, 0, 255");
      analogWrite(8, 100);
      delay(50);
      analogWrite(9, 0);
      delay(50);
      analogWrite(10, 100);
      delay(50);
      break;

    case 16244767:
      Serial.println("White, 255, 255, 255");
      analogWrite(8, 255);
      analogWrite(9, 255);
      analogWrite(10, 255);
      break;

    default:
      Serial.println(results.value);
  }// End Case

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



void setup() {
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);
  pinMode (encoder0PinS, INPUT);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);

  lcd.begin(16, 2);
  lcd.print("      Start     ");

  Serial.begin (9600);
}

void loop() {
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) &amp;&amp; (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
  }
  encoder0PinALast = n;
  if (encoder0Pos == 4) {
    encoder0Pos = 0;
  }
  if (encoder0Pos == -1) {
    encoder0Pos = 3;
  }

  MenuPos = encoder0Pos;

  Reader = digitalRead(encoder0PinS);
  // Serial.println(Reader);

  if (digitalRead(encoder0PinS) == LOW) {
    while (digitalRead(encoder0PinS) == LOW) {}
    Selected = true;
  }

  Serial.println("MenuLoop");
  switch (MenuPos) {
    case 0:
      lcd.setCursor(0, 0);
      lcd.print("     Random    ");
      while (Selected == true) {
        ranPin = random(8, 10);
        ranVal = random(0, 255);
        analogWrite(ranPin, ranVal);

        if (digitalRead(encoder0PinS) == LOW) {
          while (digitalRead(encoder0PinS) == LOW) {}
          Selected = false;
        }
      }
      break;

    case 1:
      lcd.setCursor(0, 0);
      lcd.print("       IR      ");
      Serial.println("IR Receiver Button Decode");
      irrecv.enableIRIn(); // Start the receiver

      while (Selected == true) {
        if (irrecv.decode(&amp;results)) // have we received an IR signal?
        {
          translateIR();
          irrecv.resume(); // receive the next value
          lcd.setCursor(0, 1);
          lcd.print("               ");
          lcd.setCursor(0, 1);
          lcd.print(results.value);
        }
        if (digitalRead(encoder0PinS) == LOW) {
          while (digitalRead(encoder0PinS) == LOW) {}
          Selected = false;
        }
      }

      break;

    case 2:
      lcd.setCursor(0, 0);
      lcd.print("      Temp     ");
      break;

    case 3:
      lcd.setCursor(0, 0);
      lcd.print("      Pot      ");

      while (Selected == true) {
</code></pre>

<hr>

<p>Not working</p>

<pre class="lang-cpp prettyprint-override"><code>        for (int thisPin = 8; thisPin &lt;= 10; thisPin++) {
          // fade the LED on thisPin from off to brightest:
          for (int brightness = 0; brightness &lt; 255; brightness++) {
            analogWrite(thisPin, brightness);
            delay(2);
          }
          // fade the LED on thisPin from brightest to off:
          for (int brightness = 255; brightness &gt;= 0; brightness--) {
            analogWrite(thisPin, brightness);
            delay(2);
          }
          // pause between LEDs:
          delay(100);
        }
</code></pre>

<hr>

<pre class="lang-cpp prettyprint-override"><code>        if (digitalRead(encoder0PinS) == LOW) {
          while (digitalRead(encoder0PinS) == LOW) {}
          Selected = false;
        }
      }
      break;
  }
}
</code></pre>
 4143: <p>The problem has nothing to do with your switch code. It's all to do with what you are <em>trying</em> to do, and peripherals conflicting.</p>

<p>Simply put: both PWM on pins 9 &amp; 10, and the infrared library, require exclusive use of Timer 2. </p>

<p>Only one can use it. Either the infrared library, or PWM on those two pins, but not both.</p>

<p>You can modify the IR library to use a different timer instead of Timer 2 - for instance, you can set it to use Timer 1 which will remove your ability to use pins 11 and 12 as PWM.</p>

<p><a href="https://github.com/z3t0/Arduino-IRremote/blob/master/boarddefs.h#L82" rel="nofollow noreferrer">This is the bit of code</a> that you would need to find and modify on your system to change timers.  <a href="https://playground.arduino.cc/Main/TimerPWMCheatsheet" rel="nofollow noreferrer">This page</a> shows you which timers are used for PWM on which pins.</p>
