Need Help...

hi yall im working on an arduino project and im kinda stuck…I’m trying to code a sketch that checks for an IR signal from a IR receiver and then changes a RGB led to a certain color based on what code it receives…i found some code on the internet and made the arduino receive the IR code and it changes the led when it receives a IR code…but the problem is, is that it will change the led to the color i want no matter what code is sent to the IR receiver…i tried to add an IF statement to the code with the IR code init and it still doesn’t want to work…Take a look at the code i attached and any input as to how i can make this work would be greatly appreciated! thank you

ir_Teams.ino (1.8 KB)

Not every one can read the code on their particular device. I can't on my iPad.

Put your code in its own window as seen in other posts. This can be done by placing     [code] and [/code]  around the code. This makes it easier for others to read.

Weedpharma

#include <IRremote.h>

int IRpin = 11;
IRrecv irrecv(IRpin);
decode_results results;



#define COMMON_ANODE

int redPin = 6;
int greenPin = 5;
int bluePin = 3;

void setup()
{
  //IR Reciver
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  
  
  //RBG leds
  
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT); 
  
}



void setColor(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);  
}


void loop() 
{
  
  
  if (irrecv.decode(&results)) 
    {
      Serial.println(results.value, DEC); // Print the Serial 'results.value'
      irrecv.resume();   // Receive the next value   
      
    
       
       
       
           if (results.value = 2800112845)
            {
              
                 setColor(0, 255, 255);  // team1 aqua
            }    
             
                   
            
    }
    
 }

if (results.value = 2800112845)

How did you arrive at this value?

Weedpharma

Hi,

You have made one of the most common noob mistakes when first writing code in C.

This line

if (results.value = 2800112845)

In C, when you want to compare two values you must say == not just =

One = means you want to set the value of the variable, and the result is always true, so the code inside the { } always gets run.

Also I think you have this line in the wrong place

irrecv.resume();   // Receive the next value

Try putting it after your if statement, so only two } are after the above line.

Paul

           if (results.value = 2800112845)

http://www.gammon.com.au/forum/?id=12153#trap3

PaulRB: One = means you want to set the value of the variable, and the result is always true, so the code inside the { } always gets run.

Maybe not.

It is in this case, but not in the more general case.

Fixed it!! thank you much!...haha i know... im a total newbie to the c language trying to learn tho! haha anyways thanks everybody!

PaulRB: Hi,

You have made one of the most common noob mistakes when first writing code in C.

This line

if (results.value = 2800112845)

In C, when you want to compare two values you must say == not just =

One = means you want to set the value of the variable, and the result is always true, so the code inside the { } always gets run.

Also I think you have this line in the wrong place

irrecv.resume();   // Receive the next value

Try putting it after your if statement, so only two } are after the above line.

Paul