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?
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
}