Just some IR help :)

I messed up pretty bad on this, I have no idea how to do this. I'm assuming I should redo this with unsigned char, but I don't know how to do that. My goal is just a prototype code for a controller i'm working on for my current robot project. It should be able to detect 3 joysticks and there general direction. I'm really confused with how to send the IR codes. I had tried putting the signals and encoding them through a text to hex converter, but I got the error message
"Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)
unable to find numeric literal operator 'operator""a6f79737469636b317572'"
I would be grateful for any help, thank you!
Also I know there are still really bad errors in the code besides that, i'll fix that later tonight.
Also the blob of hex at the beginning was so I could copy and paste them later, the system works like a rose compass with ur being up right etc and o being a placeholder.

#include <IRremote.h>{
#define IR_SEND_PIN 5     //key for REWORK: first number = joystick, second number = u/d/o; (1,2,3), third number = l/r/o; (1,2,3)
#define ANALOG_X_PIN1 A2  //6e65757472616c7831 (neutralx1)
#define ANALOG_Y_PIN1 A3  //6e65757472616c7931 (neutraly1)
#define ANALOG_X_PIN2 A2  //6e65757472616c7832 (neutralx2)
#define ANALOG_Y_PIN2 A3  //6e65757472616c7932 (neutraly2)
#define ANALOG_X_PIN3 A2  //6e65757472616c7833 (neutralx3)
#define ANALOG_Y_PIN3 A3  //6e65757472616c7933 (neutraly3)
//Default values when axis not actioned 22+- is the point where it is considered an action; 150/106
#define ANALOG_X_CORRECTION1 128  //1 uo 6a6f79737469636b31756f ur 6a6f79737469636b317572 or 6a6f79737469636b316f72 dr 6a6f79737469636b3164721 REWORK: 1uo (113), 1ur (112), 1or (132), 1dr (122)
#define ANALOG_Y_CORRECTION1 128  //1 do 6a6f79737469636b31646f dl 6a6f79737469636b31646c ol 6a6f79737469636b316f6c ul 6a6f79737469636b31756c  REWORK: 1do, 1dl, 1ol, 1ul
#define ANALOG_X_CORRECTION2 128  //2 uo 6a6f79737469636b32756f ur 6a6f79737469636b327572 or 6a6f79737469636b326f72 dr 6a6f79737469636b326472  REWORK: 2uo, 2ur, 2or, 2dr
#define ANALOG_Y_CORRECTION2 128  //2 do 6a6f79737469636b32646f dl 6a6f79737469636b32646c ol 6a6f79737469636b326f6c ul 6a6f79737469636b32756c  REWORK: 2do, 2dl, 2ol, 2ul
#define ANALOG_X_CORRECTION3 128  //3 uo 6a6f79737469636b33756f ur 6a6f79737469636b337572 or 6a6f79737469636b326f72 dr 6a6f79737469636b336472  REWORK: 3uo, 3ur, 3or, 3dr
#define ANALOG_Y_CORRECTION3 128  //3 do 6a6f79737469636b33646f dl 6a6f79737469636b33646c ol 6a6f79737469636b336f6c ul 6a6f79737469636b33756c  REWORK: 3do, 3dl, 3ol, 3ul
struct analogdata {
  short x1, y1, x2, y2, x3, y3;
};

IRsend irsend;

void setup()
{
  IrSender.begin();
}

void loop() {
  analogdata analogdata;

  analogdata.x1 = analogRead(ANALOG_X_PIN1) - ANALOG_X_CORRECTION1; //calculation for if the joystick is away from the origin
  analogdata.y1 = analogRead(ANALOG_Y_PIN1) - ANALOG_Y_CORRECTION1;

if ((analogdata.x1 > 150) && (analogdata.y1 > 150)) { //upright/ur command
  irsend.sendSAMSUNG(112);
}

else if ((analogdata.x1 > 150) && (analogdata.y1 < 106)) { //downright/dr command
  irsend.sendSAMSUNG(122);
}

else if ((analogdata.x1 > 150) && (analogdata.y1 > 106) && (analogdata.y1 < 150)) { //right/or command
  irsend.sendSAMSUNG(132);
}

else if ((analogdata.x1 < 106) && (analogdata.y1 > 150)) { //upleft/ul command
  irsend.sendSAMSUNG(1);
}


else if ((analogdata.x1 < 106) && (analogdata.y1 < 106)) { //downleft/dl command
  irsend.sendSAMSUNG(1);
}

else if ((analogdata.x1 < 106) && (analogdata.y1 > 106) && (analogdata.y1 < 150)) { //left/ol command
  irsend.sendSAMSUNG(1);
}

}

(current code is above)

You need to look at the examples in the IRremote library and take some time to learn very basic C++ language skills.

1 Like

In no wya am i claiming to be a good coder, as im not, but I've been coding for years. While i understand and as i said, it has many flaws, its only meant to serve as a prototype to test my controller. Ill look at the library again, ty.

What you can get with IR receive dump example?

What's the reason to use this (6a6f79737469636b317572) huge number instead hexadecimal number?

What's the reason to use structs for two variables?

1 Like

I'll try to point out the most obvious issues.

  1. There is no reason for you to create an IRsend object since the library creates one for you called IrSender
  1. You need to call the begin() method in your setup() function.

IrSender.begin();

  1. You need to define the IR send pin. You can #define IR_SEND_PIN OR include the send pin in the begin() method call.

  2. I have no idea what you are trying to do here. IRsend is a class defined by the library, not an object. Also, there are a multitude of write() and send() methods for this library none of which take the massive 11 byte hex (I assume) number you have here.

  1. Remove the ';' after the if and end if code blocks
1 Like

You can't put letters (even hexadecimal digits) in decimal numbers. At a minimum you should tell the compiler that you are using hexadecimal by adding the '0x' or '0X' prefix:

  IRsend(0x6a6f79737469636b317572)
  IRsend(0x6a6f79737469636b3164721)
  IRsend(0x6a6f79737469636b316f72)

I don't think the compiler supports integer variables larger than 64 bits (16 hexadecimal digits). For longer values you would typically create an array of bytes and specify the number of bytes.

1 Like

I had been using it because I had absolutely no idea how it worked and dint realize i could just do simple codes, ty lol
Thank you! I hadnt realized I didnt need all the structs
:slight_smile: thx for the help man

lol yeah i figured that out the hard way when i tried to compile it and fixed it by adding the 0x and a , 32 at the end. Tysm! :smiley:

Thank you! Sorry, I barely grasp IR code, thanks for the help! And yeah I got rid of all the ;, it had been in one and I copy pasted but forgot to delete them. I dont know why I put it in there at all lol. Thanks tho, this helps a lot :smile:
also, when I put IrSender.begin(); in Setup(), I got the error exit status 1
'IrSender' was not declared in this scope for some reason. Sorry if im making some stupid mistake btw.

#include <IRremote.h>{
#define IR_SEND_PIN 5    

You have an extraneous '{' after #include <IRremote.h>
You should define IR_SEND_PIN before including the library otherwise IR_SEND_PIN is undefined when the library is included! Like this:

#define IR_SEND_PIN 5    
#include <IRremote.h>

Either use the object you instantiated (irsend) or use the object IRremote instantiates for you (IrSender). You are calling the begin() method for the IrSender object but then using the irsend object (which has not been initialized properly!) later in your code. I would recommend using the one instantiated for you otherwise you are wasting memory having two objects instantiated and only using one of them.

These are fundamental issues. You may want to start with a simpler project.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.