void setup() {
Serial.begin(19200);
//Serial.println("<Arduino are ready>");
//Serial.println("");
const char myArray[][5] = {"2602", "b603", "c001","bc14","adff","fa","f40c","fa0c","2901","2a01","e4"};
// put your setup code here, to run once:
int aSize = sizeof(myArray) / sizeof(myArray[0]);
Serial.println(aSize);
for ( int x = 0; x < aSize; x++ ) {
Serial.print(x+1);
Serial.print(": ");
Serial.print(myArray[x]);
Serial.print(" : ");
Serial.println(hex2int(myArray[x]));
}
Serial.println("##");
int16_t chgVol = "0x03b6";
Serial.println(chgVol/10.0);
int16_t disVol = "0x01c0";
Serial.println(disVol/10.0);
int16_t temp= "0xfa00";
Serial.println(temp/10.0);
int myint2 = 0x00e4;
Serial.println(myint2);
myint2 =99;
char mychar2[10] = "e4";
char myhex[7] = "0x";
int arrayLen=strlen(mychar2);
Serial.println(arrayLen);
if (arrayLen == 2){
strcat(myhex,"00");
Serial.println(myhex);
}
strcat(myhex,mychar2);
Serial.println(myhex);
myint2=0;
myint2=myhex;
Serial.println(myint2);
}
void loop() {
// put your main code here, to run repeatedly:
}
int16_t hex2int(const char *hex) {
uint16_t value; // unsigned to avoid signed overflow
for (value = 0; *hex; hex++) {
value <<= 4;
if (*hex >= '0' && *hex <= '9')
value |= *hex - '0';
else if (*hex >= 'A' && *hex <= 'F')
value |= *hex - 'A' + 10;
else if (*hex >= 'a' && *hex <= 'f')
value |= *hex - 'a' + 10;
else
break; // stop at first non-hex digit
}
return value;
}
/*
351 0000: 2602 b603 b603 c001
355 `
356 0000: bc14 adff fa
35a 0000: a8aa a2
35e LEOCH
370 LEOCH
372
373 0000: f40c fa0c 2901 2a01
375 1 ::8 - 1 ::2
375 1 ::15 (15 could b 8 15 8 2 )
376 1 ::2 (seems constant)
377 1 ::3 (seems constant)
379 0000: e4
*/