1

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!

asked Feb 13, 2015 at 10:16
2
  • 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 explanation Commented 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. Commented Feb 13, 2015 at 10:34

1 Answer 1

4

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
 }
 }
 }
}
answered Feb 13, 2015 at 11:41
2
  • 2
    Great job. P.S. To make your code a bit more intuitive, you could change IRArray = 2 to IRArray = 3, and then use CountIR < IRArray for the loop. Commented Feb 13, 2015 at 11:58
  • 1
    Thanks! I'll hope this could be of some help. I'll edit my response following your advice. Many thanks for pointing that out. Commented Feb 13, 2015 at 12:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.