I have a dfrobot 38khz ir receiver module and I am having trouble using the output with any other code. When I use this code, check the serial monitor I get the correct value when I press button 3 on the remote "219E708F".
Now my problem is I cannot seem to do anything with that value. Its like it shows correctly in the serial monitor, but in reality its not the actual value. The problem lies somewhere in the if statement for the digital pin 7.
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.print(results.value, HEX);
Serial.println(" ");
Serial.println(" ");
irrecv.resume(); // Receive the next value
}
if ((results.value, HEX) == 219E708F) {
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
}
}
You cannot invent arbitrary format specifiers for results.value just because you can use that format in Serial.print(). The 0x on the start of the value to be compared indicates that it is a hex number.
Probably - it seems to me fairly unusual to print a space on its own line, but you may have a good reason we can't see.
Back in The Bad Old Days of mechanical Teletypes, after sending a carriage-return, you had to send a few padding characters or pause to allow the head to move to the start of the line, before sending any new data.
Perhaps you have a similar situation?