RGB Led Strip Arduino , Color problem

Thread Starter

JustMe234

Joined Feb 25, 2017
68
Hello,

I build the circuit for control RGB led strip with arduino using mosfets's 4 color woks great RED, GREEN, BLUE, WHITE.
But when i change to another color like PURPLE it freeze and doesn't take any command.


i have inculde my code here.
C:
#include <IRremote.h>

int redPin = 9;
int bluePin =10;
int greenPin = 11;

int RECV_PIN = 6;
int before;
int bright;
int bright1;
int steps = 10;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup(){
irrecv.enableIRIn();

before = 0;
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop(){
if (irrecv.decode(&results)){

   if(results.value == FFBA45){
     if(bright1-255/steps<0){
       analogwrite
     }
    
   }

   if (results.value == 0xFF02FD){
     if ( before == 0){
       allcolor(255,255,255);
       before = 1;
     }
     else{
       allcolor(0,0,0);
       before = 0;
       bright = bright1;
     }
   }
   if (before == 1){
      if( results.value ==0xFF1AE5){
       allcolor(255, 0, 0);
       bright = bright1;
      }
   }
   if(before ==1){
     if(results.value == 0xFF9A65){
       allcolor(0, 255, 0);
       bright = bright1;
     }
    }

    if (before == 1){
     if(results.value == 0xFFA25D){
       allcolor(0, 0, 255);
       bright = 255;
     }
    }

    if (before == 1){
     if(results.value == 0xFF2AD5){
       allcolor(153, 139, 88);
       bright = bright1;
     }
    }

    if (before == 1){
     if(results.value == 0xFFAA55){
       allcolor(88, 153, 93);
       bright = bright1;
     }
    }
  
    irrecv.resume();
}
}


void allcolor (int red, int green, int blue){
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
Moderators note: used code tags
 
Last edited by a moderator:

djsfantasi

Joined Apr 11, 2010
9,163
There are several issues in your sketch. I am not on my laptop, so I can't try to compile it, so some of my observations may be off.

  • In the first if statement in you loop() function, you apparently omitted the "0x" prefix so the test is being done against an undefined variable, FFBA45
  • Later in the same if statement, you reference something called ""analogwrite". I don't know what this is? Did you mean "analogWrite()"? As it is, it is another undefined variable.
  • You have defined two variables. Bright and bright1. Bright is set, but I don't see it used. Bright1 is used, but I don't see anywhere it is set. What?
With these problems, whatever your sketch actually does cannot be predicted.
 

Thread Starter

JustMe234

Joined Feb 25, 2017
68
Yes you are right this is the original code i have problem i upload the wrong code sorry for that.

C:
#include <IRremote.h>

int redPin = 9;
int bluePin =10;
int greenPin = 11;

int RECV_PIN = 6;
int before;
int steps = 10;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup(){
  irrecv.enableIRIn();

  before = 0;
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop(){
  if (irrecv.decode(&results)){

    bright1-255/steps<0;

    if (results.value == 0xFF02FD){
      if ( before == 0){
        allcolor(255,255,255);
        before = 1;
      }
      else{
        allcolor(0,0,0);
        before = 0;

      }
    }
    if (before == 1){
       if( results.value ==0xFF1AE5){
        allcolor(255, 0, 0);

       }
    }
    if(before ==1){
      if(results.value == 0xFF9A65){
        allcolor(0, 255, 0);
  
      }
     }

     if (before == 1){
      if(results.value == 0xFFA25D){
        allcolor(0, 0, 255);
      
      }
     }

     if (before == 1){
      if(results.value == 0xFF2AD5){
        allcolor(153, 139, 88);
    
      }
     }

     if (before == 1){
      if(results.value == 0xFFAA55){
        allcolor(88, 153, 93);
      
      }
     }
    
     irrecv.resume();
  }
}


void allcolor (int red, int green, int blue){
  #ifdef COMMON_ANODE
  red = 255 - red;
  green = 255 - green;
  blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}
Moderators note : used code tags AGAIN, Please use the code tags for pieces of code.
 

djsfantasi

Joined Apr 11, 2010
9,163
Now you have bright1 as an undefined and unused variable. If you don't need it, take it out. I can't imagine a) this sketch compiling nor b) that line doing anything useful or anything close to what you think it might.

Maybe it's time for some debug code.

Add the lines necessary to use console output. I can help if you need it.

Then, before each if statement, print out the value of "results.value".

Also, within each if statement, print out what it does.

Then, when your sketch runs, you can see what it's doing.
 

Thread Starter

JustMe234

Joined Feb 25, 2017
68
Again forgot to remove that line i dont need it know.

That's a good idea with print command i will try it and see what its the output when press the button's.

huh?
how to see what is print on serial monitor when i disconnect from PC and use a 12V adapter If i connect all together it will burn the Arduino board.

Maybe to use a LCD screen?
 

djsfantasi

Joined Apr 11, 2010
9,163
Well, I tested my code connected to the PC first. Then I could use the IDE serial monitor. I see nothing that you couldn't test without connecting to the LED strip.
 

Thread Starter

JustMe234

Joined Feb 25, 2017
68
Thanks again

After test on serial monitor it show me not FFAA55 but show me 16722645
When i press this button it freeze and doesn't respond anymore.
I don't know why this happened?

Code:
#include <IRremote.h>

int redPin = 9;
int bluePin =10;
int greenPin = 11;

int RECV_PIN = 6;
int before;


IRrecv irrecv(RECV_PIN);

decode_results results;

void setup(){
  irrecv.enableIRIn();
Serial.begin(9600);
  before = 0;
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop(){
  if (irrecv.decode(&results)){


    if (results.value == 0xFF02FD){
      if ( before == 0){
        allcolor(255,255,255);
        before = 1;
      }
      else{
        allcolor(0,0,0);
        before = 0;

      }
    }
    if (before == 1){
       if( results.value ==0xFF1AE5){
        allcolor(255, 0, 0);
  
        Serial.println(results.value);
       }
    }
    if(before ==1){
      if(results.value == 0xFF9A65){
        allcolor(0, 255, 0);
        
        Serial.println(results.value);
      }
     }

     if (before == 1){
      if(results.value == 0xFFA25D){
        allcolor(0, 0, 255);
        bright = 255;
        Serial.println(results.value);
      }
     }

     if (before == 1){
      if(results.value == 0xFF2AD5){
        allcolor(153, 139, 88);
        
        Serial.println(results.value);
      }
     }

     if (before == 1){
      if(results.value == 0xFFAA55){
        allcolor(88, 153, 93);
        
        Serial.println(results.value);
      }
     }
    
     irrecv.resume();
  }
}


void allcolor (int red, int green, int blue){
  #ifdef COMMON_ANODE
  red = 255 - red;
  green = 255 - green;
  blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}
 

djsfantasi

Joined Apr 11, 2010
9,163
You still are using undefined variables. I have no clue why the compiler isn't flagging them.

The value printed is the decimal equivalent of the hex value.
 
Top