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?
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@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.
I had a psychic girlfriend but she left me before we met.
@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
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@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!!!
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
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 */};
I had a psychic girlfriend but she left me before we met.
@tanuki Unless you post your entire code we can do nothing.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting