Fade sequence not working

I have a project where I want 6 led's to fade in an out once triggered by and IR device. When I run the fading code by it's self all 6 led's behave as they should but once I introduce the IR code 2 out of the 6 lights will randomly blink and never fade like the others.

I've attached a video of this as well as the code, I'd appreciate any help....thank you!

Few will download the code as preferred method is to put it into the forum... I know file-sharing is efficient, but for now the forum spirit is to put it online here.

To assist, I have put it here.

#include <IRremote.hpp>

int IRpin=2;
IRrecv IR(IRpin);
decode_results cmd;
String myCom;

int ledPinYELLOW = 9;    // LED connected to digital pins
int ledPinGREEN = 10;
int ledPinORANGE = 6;
int ledPinRED = 5;
int ledPinBLUE = 3;
int ledPinWHITE = 11;
int ms=5;

void setup()
{
Serial.begin(9600);
IR.enableIRIn();


}
 
void loop() {
  while (IR.decode(&cmd)==0){ 
}
delay(1500);
IR.resume();
 
if (cmd.value==0xFF6897){
  myCom="zero";
  Serial.println(myCom); 
}
if (cmd.value==0xFF30CF){
  myCom="one";
  Serial.println(myCom); 
}
if (cmd.value==0xFF18E7){
  myCom="two";
  Serial.println(myCom); 
}
if (cmd.value==0xFF7A85){
  myCom="three";
  Serial.println(myCom); 
}
if (cmd.value==0xFF10EF){
  myCom="four";
  Serial.println(myCom); 
}
if (cmd.value==0xFF38C7){
  myCom="five";
  Serial.println(myCom); 
}
if (cmd.value==0xFF5AA5){
  myCom="six";
  Serial.println(myCom); 
}
if (cmd.value==0xFF42BD){
  myCom="seven";
  Serial.println(myCom); 
}
if (cmd.value==0xFF4AB5){
  myCom="eight";
  Serial.println(myCom); 
}
if (cmd.value==0xFF52AD){
  myCom="nine";
  Serial.println(myCom); 
}
 
if (cmd.value==0xFFA25D){
  myCom="pwr";
  Serial.println(myCom); 
}
if (cmd.value==0xFF629D){
  myCom="v+";
  Serial.println(myCom);
}
if (cmd.value==0xFFE21D){
  myCom="fun";
  Serial.println(myCom);
}
if (cmd.value==0xFF22DD){
  myCom="rew";
  Serial.println(myCom);
}
if (cmd.value==0xFF02FD){
  myCom="play";
  Serial.println(myCom);
}
if (cmd.value==0xFFC23D){
  myCom="ff";
  Serial.println(myCom);
}
if (cmd.value==0xFFE01F){
  myCom="dn";
  Serial.println(myCom);
}
if (cmd.value==0xFFA857){
  myCom="v-";
  Serial.println(myCom);
}
if (cmd.value==0xFF906F){
  myCom="up";
  Serial.println(myCom);
}
if (cmd.value==0xFF9867){
  myCom="eq";
  Serial.println(myCom);
}
if (cmd.value==0xFFB04F
){
  myCom="st";
  Serial.println(myCom);
}
if (myCom=="one")
// Sequence 1
  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinYELLOW, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinYELLOW, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }

  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinGREEN, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinGREEN, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }
    // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinORANGE, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinORANGE, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }
      // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinRED, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinRED, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }
        // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinBLUE, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinBLUE, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }
          // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinWHITE, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinWHITE, fadeValue);
    // wait for ms milliseconds to see the dimming effect
    delay(ms);
  }
 
}

The code as posted compiles, BUT around line #116 you have:

 if (myCom == "one")
    // Sequence 1
    // fade in from min to max in increments of 5 points:

I suspect you need a "{" and a matching "}" to indicate a block of logic.

You should also study:
switch...case - Arduino Reference

The IRremote library uses Timer1 so you can't use hardware PWM (analogWrite()) on pins 9 and 10 when you use IRremote.

johnwasser, the lights that are having the problem are on pin's 11 & 3, pins 9 & 10 work fine.

Thank you mrburnette, this is my first post I wasn't sure which way to post the code.

I tried adding {} before and after the if statement but I get an error saying "expected primary-expression before'}' token."

Maybe they changed the default timer. Same effect, different pins.

I'm using an Uno would a different board work?

Yes. An Arduino MEGA 2560 has more timers and many more PWM pins.

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