jusme
April 4, 2012, 1:49am
#1
Cant get it to display a simple floating point. anybody help me figure out what to do. I tried the code below,
char xtr[20];
float x;
x=.01;
void loop(){
x++;
sprintf(xtr,"x= %f ",x);
Tft.fillRectangle(0,140,144,16,0);//fill area with black (clear text)
Tft.drawString(xtr,0,140,2,WHITE);
Thanks.
deray
April 5, 2012, 3:24am
#2
I had the same problem, like the arduino sprintf doesn’t work, finally can only try to write their own floating point the transformation of the function character groups.
jusme
April 6, 2012, 2:26am
#3
not sure I get what you mean, how did you figure it out?
deray
April 10, 2012, 7:23am
#5
you can try this function that change “float” to “string”.
int digits :the number of digits behind decimal point
[code]char *_ftoa(double n, char *s, int digits)
{
memset(s , 0 , sizeof(s));
int i = 0 , p;
char sign = true;
if( n < 0 )
{
sign = false;
n = -n;
}
long long t = (long long)n;
n = n - t;
if( t == 0)
{
s[i++] = ‘0’;
}
else
{
while( t != 0 )
{
p = t % 10;
t /= 10;
s[i++] = p + ‘0’;
}
if(!sign) s[i++] = ‘-’;
}
if( fabs( n - 0.0 ) > 0.0000000000001)
{
s[i++] = ‘.’;
int cur_d = 0;
while( cur_d < digits)
{
cur_d++;
n *= 10.0;
p = (long long)n;
n = n - p;
s[i++] = p + ‘0’;
}
}
s[i] = ‘\0’;
}[/code]