String to byte (ex. String b = "0xc7"; to byte b = 0xc7;)
i trying convert strings formatted string byte1 = "0xc7"; bytes can use serial write send them gas sensor using project calibration process. i've been searching web , have been unable come across solution works me.
any appreciated!
any appreciated!
code: [select]
//convert user inputted calibration offset ieee 754
string hexoffset = decimaltofloatinghex(offset); //returns string "42c70000"
string byte1 = "0x" + hexoffset.substring(hexoffset.length() - 2, hexoffset.length());
string byte2 = "0x" + hexoffset.substring(hexoffset.length() - 4, hexoffset.length() - 2);
string byte3 = "0x" + hexoffset.substring(hexoffset.length() - 6, hexoffset.length() - 4);
string byte4 = "0x" + hexoffset.substring(hexoffset.length() - 8, hexoffset.length() - 6);
byte spanmethane2[13] = {0x10, 0x1a, 0x06, byte1, byte2, byte3, byte4, 0x01, 0x00, 0x10, 0x1f, 0x01, 0x69};
serial1.write(spanmethane2, sizeof(spanmethane2)); //sends readcommand array sensor.
just don't store them 0xc7 , don't store them in string 
where variables coming from?

where variables coming from?
Arduino Forum > Using Arduino > Programming Questions > String to byte (ex. String b = "0xc7"; to byte b = 0xc7;)
arduino
Comments
Post a Comment