How to use IR received codes.

Hi guys. I am working on a project for school, I am turning a small RC car into a vehicle with Adaptive Cruise Control. I'm trying to make it start/stop using a remote that came with the Arduino package but I can't use the data I'm getting! This is what I have written:

#include <IRremote.h>

int RECV_PIN = 11;
int ch;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC);
    irrecv.resume(); // Receive the next value
  }

ch=(results.value);

if (ch=6375) { 
do this
}
else if (ch=12495) {
do that
}
}

Although "ch" is getting those particular integers, it won't listen to the "ifs" and proceed anyway with the code in the { }. What am I doing wrong here?

Thanks!

Classic C issue. Instead of this:

if (ch=6375)

you want this:

if (ch==6375)

At a guess I assume that the results are in results so move irrecv.decode(&results) to before the if and then put results in the if like so -

uint8_t bSuccess = irrecv.decode(&results);

if(sSuccess) // success means we got something, you might want to do something 'else' if we didnt in which case put it in the else
{
  // use results here ...

}
else
{
  // do something if we didnt get anything from decode
}

Duane B

rcarduino.blogspot.com

wildbill:
Classic C issue. Instead of this:

if (ch=6375)

you want this:

if (ch==6375)

Oh my god I can't believe I fell for this...thanks dude and sorry for wasting precious internet database space :stuck_out_tongue:

Sorry chaps, didn't scroll down to see the rest of the code and as such my response is useless :blush:

Duane B

np Duane perhaps your site will be useful for my project! Thanks

ch=(results.value);

The decode_results class says that value is an unsigned long. No way are you going to fit that in a char.