Go Down

Topic: Servo position value, can it be real number? (Read 870 times) previous topic - next topic

MilanV

As the topic says, can a value of a Servo position be a real number like 43.5 and not integer??
Code: [Select]

myservo.write(43.5);

I didn't know where to post this question, whether here or at "motors" part of the arduino forum. Thanks!

AWOL

No.
A floating point argument will simply be truncated.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


AWOL

If you need finer control, you can use the writeMicroseconds method.
However, asking for fractional degree accuracy of an R/C servo may be asking a bit much.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

robtillaart

Quote
A floating point argument will simply be truncated.


You might add 0.5 to get proper rounding

float angle = 43.4;
myservo.write(angle + 0.5);  ==> 43 degrees

float angle = 43.6;
myservo.write(angle + 0.5);  ==> 44 degrees
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Go Up