If I replace the first parameter with a int variable (temp = 0x22C) it also works fine. Now I would want to make it work with any number like I could be composing a string (i.e. "0x" + int + "C") ... which function should I use for the conversion?
Tks
Flavio
I moved your topic to an appropriate forum category @flavios.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
If I got it right... your line does not work, the result of 27*16+0xC is 1BC (that shows on the display as 1bC) - if I add one to yout t variable it goes 1CC so I won't be able to put the temp there ... sure there must be a way to write a function to put 22 decimal and shift it left to allow for the last 0xC digit and make it displayed as HEX.
We'd want 0x220 0x230 0x240 ... so 22 HEX to DEC = 34 * 16 + 0xC = 22C
The conversion of a string should be less complex. Or go to binary?
Flavio
This sketch demonstrate it...
int t = 0;
int tx = 0x1;
void setup() {
Serial.begin(115200);
Serial.println("Inizialize SERIAL...");
}
void loop() {
t = 27;
tx = t*16+0xC;
Serial.println(tx, HEX);
}
I did read it. This does not guarantee that I got it right ... sure I found no line 42 (in the example, the header or the .cpp)
I wonder if you refer to using the other function with a DEC input. This works (I used it for the temp negative values) BUT I cannot add the "C" for Centigrade that casually is also an HEX number.
I could write something more complex using the individual segments, but I was just asking to avoid it for a more elegant solution...
Flavio
If you have an int variable that is the temperature, just pass it in like you are with the constants.
It's a number, it's holding the value of some temperature. There is no need to shoehorn it into a textual representation of a hexadecimal number so it looks the same as 0x22C or whatever.
I agree there is no need to translate to a text representation, but some shoehorning may be required to translate the temperature value into BCD and then append the "C" digit before displaying it.
Hmm... negative values are supported automatically for decimal, but then you can't use the C/F trick. showNumberHexEx takes a uint16_t, so the coldest would be 0F. But looks like you can use showNumberBaseEx and pass -16 as the base, and get down to -99C.
Then it's just doing the int to BCD conversion, and since the numbers are limited to three digits -- you'll want to clamp them at the min/max -- it's pretty straightforward.
I would probably try it with 2 calls. First with length = 3, pos = 0 for setting the number.
The second with length = 1, pos = 3 for setting the C.
This would avoid the conversion decimal -> BCD.