Hello!
I am asking for some help. It is about IR signals using ESP32 and arduino as compiler.
I need to compare the received IR signal from a remote control (e.g. 1F0030) with a text (e.g. ciao). How I can do?
The received text should be in results.value and it is correctly displayed in the serial monitor. But something like:
if (results.value == ciao) { do this and that}
does not works.
Thank you in advance 🙂
Pierluigi
void loop() { if (irrecv.decode(&results)) { serialPrintUint64(results.value, HEX); Serial.println(""); irrecv.resume(); // Receive the next value } delay(100); }
Hello!
I am asking for some help. It is about IR signals using ESP32 and arduino as compiler.
I need to compare the received IR signal from a remote control (e.g. 1F0030) with a text (e.g. ciao). How I can do?
The received text should be in results.value and it is correctly displayed in the serial monitor. But something like:
if (results.value == ciao) { do this and that}
does not works.
Thank you in advance 🙂
Pierluigi
void loop() { if (irrecv.decode(&results)) { serialPrintUint64(results.value, HEX); Serial.println(""); irrecv.resume(); // Receive the next value } delay(100); }
I don't really understand your question. Are you having a problem because you do not know how to get the data, or do you not know how to do a string comparison?
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@tanuki
First, a quick Google seems to indicate that
irrecv.decode(&results)
has been deprecated, so the example that you copied is out of date.
Second, the value will have been read in and translated to a C string (of bytes) or a String object and you'll have to do your comparison with "ciao" in such a way as to match the data type of that result. You'll need to read the instructions or check the library to determine which data type to use.
Anything seems possible when you don't know what you're talking about.
@tanuki There are a lot of libraries for IR, unfortunately, there is no easy way to decide which to use. I used this one HERE and used it to dump the IR data I was getting from a ceiling fan remote. There are 23 example sketches, hopefully, one of them will be helpful to at least become the base of what you need.
As @will said, you need to determine the data type(s) and use the applicable comparison for each type.
BTW, this is one of the best documented libraries I have ever seen. Install the usual way from a zip file using the Sketch/Include Library/Add .ZIP library
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander Hi, thanks for your answer!
Basically I do not know how to compare two string.
The command
serialPrintUint64(results.value, HEX);
prints on the serial monitor a text string (from an IR signal). I would like to compare that text with another text (e.g. Hello).
Thank you!
@will Hi thanks for your answer! The text string I receive is printed in the serial monitor by
serialPrintUint64(results.value, HEX);
but I do not know how to retrieve that string and compare it with "ciao". Thanks!
@tanuki Have you tried to google? IIRC, it's something along the lines of strcmp( stuff ) or memcmp( stuff ) or strncmp if you want to limit the length it's all documented.
It comes up in google on the first page.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander thank you! I checked the command string, however I do not know how to call
serialPrintUint64(results.value, HEX);
inside a command like strcmp. (I use to code in matlab and i m new to c++, sorry)
@tanuki WHAT???? I don't understand anything you are saying!!!
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Since you don't provide any information, we can't really help you without making a lot of wild assumptions.
Assuming that results.value is an unsigned 64 bit integers which you have loaded with a set of ASCII characters as a C string and assuming that you don't want to compare it against the contents of the variable called ciao but you actually want to compare it to the text string "ciao" you might try something like ...
char test="ciao";
if ( strcmp(test,(char*)&results.value)==0 ) { /* do something here if they match */};
Anything seems possible when you don't know what you're talking about.
@tanuki Unless you post your entire code we can do nothing.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@will Thank you very much! That is the command I was looking for! It really help 🙂
@tanuki That is what I told you earlier. Also, note that @will said 'assumptions'. His example assumes several things that can trip you up so read the documentation.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.