• Welcome to LusoRobótica - Robótica em Português.
 

Sensor temperatura LM35DZ

Started by joaopedrocmp, 31 de March de 2012, 21:04

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

joaopedrocmp

Boas outra vez,

Entretanto experimentei esta função , mas continua igual:

void printDouble( double val, byte precision){
  // prints val with number of decimal places determine by precision
  // precision is a number from 0 to 6 indicating the desired decimial places
  // example: printDouble( 3.1415, 2); // prints 3.14 (two decimal places)

  Serial.print (int(val));  //prints the int part
  if( precision > 0) {
    Serial.print("."); // print the decimal point
    unsigned long frac;
    unsigned long mult = 1;
    byte padding = precision -1;
    while(precision--)
mult *=10;

    if(val >= 0)
frac = (val - int(val)) * mult;
    else
frac = (int(val)- val ) * mult;
    unsigned long frac1 = frac;
    while( frac1 /= 10 )
padding--;
    while(  padding--)
Serial.print("0");
    Serial.print(frac,DEC) ;
  }
}