Da ein writeFloat(...), z.B. zur Ausgabe der Akkuspannung oder von Messwerten fehlt, hier eine Ergänzung:
Code:
void float2string(float value, int decimal, char* valuestring)
{
int neg = 0;
char tempstr[20];
int i = 0;
int j = 0;
int c;
long int val1, val2;
char* tempstring;
tempstring = valuestring;
if (value < 0){ neg = 1; value = -value; }
for (j=0; j < decimal; j++) {value = value * 10;}
val1 = (value * 2);
val2 = (val1 / 2) + (val1 % 2);
while (val2 !=0){
if ((decimal > 0) && (i == decimal)){
tempstr[i] = (char)(0x2E);
i++;
}
else{
c = (val2 % 10);
tempstr[i] = (char) (c + 0x30);
val2 = val2 / 10;
i++;
}
}
if (neg){
*tempstring = '-';
tempstring++;
}
i--;
for (;i > -1;i--){
*tempstring = tempstr[i];
tempstring++;
}
*tempstring = '\0';
}
float Ubatt = 10.21; // Beispiel
char text[6];
float2string(Ubatt,2,text); // 2 Dezimalstellen
writeString(text); // o.ä. z.B. auf das Display
Lesezeichen