|
回復 1# everythingqq
先拔掉馬達電源,加入
Serial.print(angle);
delay(2);
Serial.print("\n");
用手前後輕微擺動車子,
看看angle的值,是否如你預期?
how to print float number:
double x;
double y;
double z;
void printDouble( double val, unsigned int precision){
// prints val with number of decimal places determine by precision
// NOTE: precision is 1 followed by the number of zeros for the desired number of decimial places
// example: printDouble( 3.1415, 100); // prints 3.14 (two decimal places)
Serial.print (int(val)); //prints the int part
Serial.print("."); // print the decimal point
unsigned int frac;
if(val >= 0)
frac = (val - int(val)) * precision;
else
frac = (int(val)- val ) * precision;
Serial.println(frac,DEC) ;
}
void setup(){
Serial.begin(9600);
Serial.println("Print floating point example");
printDouble( 3.1415, 100); // example of call to printDouble to print pi to two decimal places
x = 10;
y = 3.1;
z = x / y;
}
void loop(){
printDouble(z,10); // one decimal place
printDouble(z,100); // two decimal places
printDouble(z,1000); // three decimal places
z = z + .1;
delay(100);
} |
|