Pages: [1]   Go Down
Author Topic: Servo position value, can it be real number?  (Read 615 times)
0 Members and 1 Guest are viewing this topic.
Serbia
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As the topic says, can a value of a Servo position be a real number like 43.5 and not integer??
Code:
myservo.write(43.5);
I didn't know where to post this question, whether here or at "motors" part of the arduino forum. Thanks!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No.
A floating point argument will simply be truncated.
Logged

"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.

Serbia
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 thanks!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12482
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Tillaart

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

Serbia
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys.
Logged

Pages: [1]   Go Up
Jump to: