Hi,
I'm sorry for my bad english.
For a project im using a Arduino UNO and a Seeduino CAN-BUS shield. Im using the Arduino Library of the shield to send CAN messages.
I want to create a function where I want to convert INT value (from sensorvalue) to a array of HEX values. A CAN message is 8 bytes long and is send like this with the library of the shield :
unsigned char st[8] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
CAN.sendMsgBuf(0x301, 0, 8, st);
As example I used int cantxValue = 4112.
And then I tried some stuff like transforming cantxValue to a HEX string ("1010") and then filled it up with zeros until it had length of 16 (1 byte is 2 digits in HEX --> 16 digits for 8 bytes).
But now I want to find how cut this string and put them in an unsigned char array (canMsg) of length 8 with a prefix of "0x" for each part of that string.
Maybe I am overthinking the problem and there is a faster/easier way. Can someone help me? I getting crazy about this problem. Im not really a good programmer but I am willing to learn.