I'm having a bit of a problem when sending IR Codes stored in variables. I swear I had this convered up already. I don't actually know the reason why I can't use variables in the first place. I receive data over Bluetooth Serial Com and I'm using an Arduino ProMicro as ISP for the Arduino Nano.
I want to send data over Serial comm and then send an IR code to the end receiver.
Here is some of the code():
#include <IRremote.h> // IR Library - Encode/Decode
void irSerial( char SerChar[] ) // Receive array of characters
char IDChar[]={'s', 'i', 'u'}; // List of Serial Char to identify position
String HRD[]={"Power", "Input", "ChaUp"}; // Action referece
byte CodesIR[]={0x61A0F00F, 0x61A048B7, 0x61A050AF}; // IR Codes
int IRArray = 2; // Size Of The array
if ( SerChar[0] == 's' ) { // Compare Array
for (int CountIR = 0; CountIR <= IRArray; CountIR++){ // Loop through array
if ( SerChar[0] == IDChar[CountIR]) {
bluetooth.println(HRD[CountIR]); // Send String in array - Works
SendIR.sendNEC(CodesIR[CountIR],32); // Send IR in array position
}
}
}
}
There's not a problem with the current expression as it compiles normally and I can send serial data normally finishing the function. If I replace the array CodesIR[CountIR] for example with 0x61A0F00F then it works perfectly.
How can I use a variable instead? Can anyone help? It is the byte CodesIR[] ??
I used a Switch/Case and it works but I prefer a variable/array and less useless coding. Thanks for understanding!
-
What are you trying to achieve? I don't know what library you're using, but it seems to me that you try to compare if SerChar[0..2] is equal to IDChar[0..2], and send the corresponding code for those that are equal. Maybe you could include a bit more code or an explanationAllanNorgaard– AllanNorgaard2015年02月13日 10:27:00 +00:00Commented Feb 13, 2015 at 10:27
-
Well yes I'm comparing those values based on what I receive over serial. Everything works fine. The thing is that it seems I'm not using the correct data type for the IR codes. I'll rephrase my question! Thanks for your concern.DarkXDroid– DarkXDroid2015年02月13日 10:34:52 +00:00Commented Feb 13, 2015 at 10:34
1 Answer 1
Well as usual it was something stupid (-__-) I changed the byte array for long and it worked perfectly.
Here is the complete code working():
#include <IRremote.h> // IR Library - Encode/Decode
void irSerial( char SerChar[] ) { // Receive array of characters
char IDChar[]={'s', 'i', 'u'}; // List of Serial Char to identify position
String HRD[]={"Power", "Input", "ChaUp"}; // Action reference
long CodesIR[]={0x61A0F00F, 0x61A048B7, 0x61A050AF}; // IR Codes
int IRArray = 3; // Size Of The array # Edit
if ( SerChar[0] == 's' ) { // Compare Array
for (int CountIR = 0; CountIR < IRArray; CountIR++){ // Loop through array # Edit
if ( SerChar[0] == IDChar[CountIR]) {
Serial.println(HRD[CountIR]); // Send String in array - Works
SendIR.sendNEC(CodesIR[CountIR],32); // Send IR in array position
}
}
}
}
-
2Great job. P.S. To make your code a bit more intuitive, you could change
IRArray = 2
toIRArray = 3
, and then useCountIR < IRArray
for the loop.Gerben– Gerben2015年02月13日 11:58:12 +00:00Commented Feb 13, 2015 at 11:58 -
1Thanks! I'll hope this could be of some help. I'll edit my response following your advice. Many thanks for pointing that out.DarkXDroid– DarkXDroid2015年02月13日 12:06:08 +00:00Commented Feb 13, 2015 at 12:06
Explore related questions
See similar questions with these tags.