I have been playing with the IR library and it was simple until I started to use it out side what it was designed for, go figure. I am attempting to use more than one receive pin and collect different code from each receive pin. I started with the library on this site and found that Ken Shirriff has already made changes to his library to use multiple receivers. I have deleted the old library and installed the new ir library from github. and then worked through the compiling errors with the help of nice people on this forum. Now I am still stuck and would like help with the actual ir functions and there syntax so I can understand it enough to modify. I have included the link for everyone to find the library I am working with. I have also included the example sketch that ken wrote and included in his library. The reference here in this Forum is great but when you get to the libraries new functions it can get overwhelming for a fairly new programmer. At the bottom I have inserted the code that does receive from two different receivers and lights up the LEDs. now I need to return the results from each receive pin. and do something with each value.
Thanks in advance and sorry for such along post, but I believe this will help many other rookies that will try this in the future.
Questions:
(irrecv.decode(&results)) results should have a value that i can return and do something with can someone break this down for me.
decode_results results; is this the same type of function without the parentheses around the results?
//Serial.print(results_8, HEX) is in the bottom code what am I doing wrong.
void setup()
{ Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) { Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
current code that I have been working on.[/size][/size]
#include <IRremote.h>
int RECV_PIN_11 = 11; //individual receivers
int RECV_PIN_10= 10; //individual receivers
int RECV_PIN_9 = 9; //individual receivers
int RECV_PIN_8 = 8; //individual receivers
int RELAY_PIN_11 = 13; //red led
int RELAY_PIN_10 = 12; //yellow led
int RELAY_PIN_9 = 15; //green led future
int RELAY_PIN_8 = 16; //blue led future
IRrecv irrecv_11(RECV_PIN_11); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_11;
IRrecv irrecv_10(RECV_PIN_10); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_10;
IRrecv irrecv_9(RECV_PIN_9); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_9;
IRrecv irrecv_8(RECV_PIN_8); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_8;
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
irrecv_11.enableIRIn(); // Start the receiver
irrecv_10.enableIRIn(); // Start the receiver
irrecv_9.enableIRIn(); // Start the receiver
irrecv_8.enableIRIn(); // Start the receiver
}
int on_11 = 0;
int on_10 = 0;
unsigned long last = millis();
void loop() {
if (irrecv_11.decode(&results_11)) { //if loop controls action of input on pin 11
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250) {
on_11 = !on_11;
digitalWrite(13, on_11 ? HIGH : LOW);
//Serial.print(results_11->value, HEX)
}
last = millis();
irrecv_11.resume(); // Receive the next value
}
if (irrecv_8.decode(&results_8)) { //if loop controls action of input on pin 11
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250) {
on_10 = !on_10;
digitalWrite(12, on_10 ? HIGH : LOW);
//Serial.print(results_8, HEX)
}
last = millis();
irrecv_8.resume(); // Receive the next value
}
}
(irrecv.decode(&results)) results should have a value that i can return and do something with can someone break this down for me.
results is a struct that is populated by irrecv.decode(). The struct has a member, value, that contains the code from the IR button. It is results.value that you need to use to decide what to do/return from some function.
decode_results results; is this the same type of function without the parentheses around the results?
No. It is where the struct is instantiated. The struct's type is decode_results, and the instance is called results.
//Serial.print(results_8, HEX) is in the bottom code what am I doing wrong.
//Serial.print(results_8, HEX)
Is trying to print a struct instance, in HEX format. This makes no sense. You might want to print results_N.value.
I have tried that and have shared below how I wrote it. I believe that I am doing something wrong with the struct. In the original code there was only one struct and I added three more. Does it make a difference if they are global? I have also included that code below. Here is the error. 'print(long long unsigned int&)' is ambiguous
if (irrecv_8.decode(&results_8)) { //if loop controls action of input on pin 8
Serial.print (results_8.value)
IRrecv irrecv_8(RECV_PIN_8); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_8;
Sorry I did not explain, but the entire code is in the original post above. Here it is again. but remember if you try it, remember I am not using the standard Ir library. I do have a link to that library here. http://github.com/shirriff/Arduino-IRremote/tree/dev .
#include <IRremote.h>
int RECV_PIN_11 = 11; //individual receivers
int RECV_PIN_10= 10; //individual receivers
int RECV_PIN_9 = 9; //individual receivers
int RECV_PIN_8 = 8; //individual receivers
int RELAY_PIN_11 = 13; //red led
int RELAY_PIN_10 = 12; //yellow led
int RELAY_PIN_9 = 15; //green led future
int RELAY_PIN_8 = 16; //blue led future
IRrecv irrecv_11(RECV_PIN_11); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_11;
IRrecv irrecv_10(RECV_PIN_10); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_10;
IRrecv irrecv_9(RECV_PIN_9); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_9;
IRrecv irrecv_8(RECV_PIN_8); //TSOP4838 Connected one at a time so there is no crosstalk
decode_results results_8;
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
irrecv_11.enableIRIn(); // Start the receiver
irrecv_10.enableIRIn(); // Start the receiver
irrecv_9.enableIRIn(); // Start the receiver
irrecv_8.enableIRIn(); // Start the receiver
}
int on_11 = 0;
int on_10 = 0;
unsigned long last = millis();
void loop() {
if (irrecv_11.decode(&results_11)) { //if loop controls action of input on pin 11
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250) {
on_11 = !on_11;
digitalWrite(13, on_11 ? HIGH : LOW);
//Serial.print(results_11->value, HEX)
}
last = millis();
irrecv_11.resume(); // Receive the next value
}
if (irrecv_8.decode(&results_8)) { //if loop controls action of input on pin 8
Serial.print (results_8.value)
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250) {
on_10 = !on_10;
digitalWrite(12, on_10 ? HIGH : LOW);
}
last = millis();
irrecv_8.resume(); // Receive the next value
}
}
One more reminder. When you use the IR library. when using the newer IDE you have to find the IRremoteInt file in the library folder and change the include statement. The #include needs to be changed to #include <Arduino.h>. Your sketch will not compile if you do not do this.
Paul when I strike the serial print line out my sketch it compiles fine. It shows the I have a lot of room left. ( Binary sketch size: 10,444 bytes (of a 258,048 byte maximum)) I am not understanding. your post. Am I generating a number too large in the serial print statement?
Am I generating a number too large in the serial print statement?
No. In the code you supplied, you have:
Serial.print (results_8.value)
There is no ; on the end of that statement, so the code fails to compile. Add one, or comment out the incomplete statement, and the code compiles. You did one. I did the other.