Hi!
As I said in other post, I am building a packet to send by digimesh mode on xbee S1.
I am having some problems with conversion types.
I have a function which converts from int to string called String dec2hex(int value). With this function I introduce my sensor value and get an hex value (string):
String dec2hex(int sensor){
char hexadecimal[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
String respuestaHex="";
int valor = sensor;
do{
respuestaHex.concat(hexadecimal[valor%16]);
valor = valor / 16;
}
while(valor%16 != 0);
return flipString(respuestaHex); //I have to invert values because I get the hex number wrong. If I have to get 74D I get D47, so I invert it. I also did flipString function
After that, I want to introduce all sensor values in hex to a byte array:
byte packet[21];
to send it by Serial:
for(int x = 0; x < packetSize; x++){ //packetSize is defined upside. It is 21
Serial.write(packet[x]);
}
But when I try to do this:
packet[17] = dec2hex(sensor1);
I got this error: hexadecimalOperaciones:134: error: cannot convert 'String' to 'byte' in assignment
I want to know if an easier way to convert number to hex exists to get it works. Also I need another fuction to convert from hex to decimal. For the moment I am using another function which gets a string and gives an int but I have the problem that it will receive a byte not a string.