Hello,
I want to calculate Pressure.
As for example:
p=x* y=xy
and as an answer it hast to be displayed on LCD in Scientific Notation like :
1.2*10²
how do I program something like this?
--Gizi
Hello,
I want to calculate Pressure.
As for example:
p=x* y=xy
and as an answer it hast to be displayed on LCD in Scientific Notation like :
1.2*10²
how do I program something like this?
--Gizi
While p is less than 1.0 multiply by 10 and decrement the display exponent. While p is higher/same 10.0 divide by 10 and increment the exponent.
Do your LCD is able to display superscript font need to print it?
The dtostre() function can format the number in scientific notion, but it will be in the form x.xexx you can edit that to replace 'e' with '*', and place the exponent as a superscript if needed, but a simple LCD display generally does not supports superscripts.
no idea. Can you tell me how to find out?
thx, will try it tomorrow
what about 1.2 10^2
consider
Output:
func: 98765.43, p 4, sc 9.88, dec 9, frac 876, 9.876 *10^4
9.876 *10^4
Code:
char buf [80];
char *
func (
double f,
int nDigits,
char *buf)
{
Serial.print (__func__);
Serial.print (": ");
Serial.print (f);
int p = log (f)/log(10);
float sc = f / pow(10, p);
int dec = sc;
int frac = (sc - dec) * pow(10, nDigits);
Serial.print (", p ");
Serial.print (p);
Serial.print (", sc ");
Serial.print (sc);
Serial.print (", dec ");
Serial.print (dec);
Serial.print (", frac ");
Serial.print (frac);
char fmt [20];
sprintf (fmt, "%%d.%%0%dd *10^%%d", nDigits);
sprintf (buf, fmt, dec, frac, p);
Serial.print (", ");
Serial.print (buf);
Serial.println ();
return buf;
}
void
setup (void)
{
Serial.begin (9600);
double f = 98765.4321;
Serial.println (func (f, 3, buf));
}
void
loop (void)
{
}
xx.xxExx for example 1.00E-06 is a common convention, what is wrong with it?
Problem is not every1 understands it, sad but true
with programming languages only.
Looks gr8, so basicly "f" should be the answer to the formula?
f= x * y;
and it would be then displayed on the display like
Worked like a charm!
Thx
and calculators
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.