servo.write(angle) question

does the servo.write(angle) function support decimal values for the angle?

If you look in the documentation you will find the type of the parameter. Does this type support the "decimal point" or not?

Mark

does the servo.write(angle) function support decimal values for the angle?

You can express the value in decimal, hex, octal or binary. Single ASCII characters, even.

sorry i used wrong term. when i said decimal what i meant was values with decimal point, like 82.15 degrees

Well, you can, but because the method accepts "int" parameters, any fractional part will be truncated. If you require better resolution, look at the writeMicroseconds method.

when i said decimal what i meant was values with decimal point, like 82.15 degrees

Did you look at the documentation for the function?

On second thought forget it. The documentation doesn't describe the type. The source does, and it isn't float.

If you think about it, though, does setting the angle to 82.15 degrees vs. 82 make sense? Is your servo capable of more than 1 degree resolution? Hobby servos certainly aren't.

You can less than one degree resolution using writeMicroseconds().

PaulS:

when i said decimal what i meant was values with decimal point, like 82.15 degrees

Did you look at the documentation for the function?

On second thought forget it. The documentation doesn't describe the type. The source does, and it isn't float.

If you think about it, though, does setting the angle to 82.15 degrees vs. 82 make sense? Is your servo capable of more than 1 degree resolution? Hobby servos certainly aren't.

You can less than one degree resolution using writeMicroseconds().

I would take some slight exception to that statement, unless some datasheet or other hard data can be shown. I'm of the opinion that most or at least many hobby R/C servos are capable of better then 180 steps of resolution. However one must utilize the servo.microSeconds() command to get the best resolution possible from any specific servo.

Lefty

thanks for the replies

I know this is old, but this thread absolutely saved me from having to buy a new servo. I accidentally bought a standard servo, and after modifying it for continuous rotation, couldn't get it to stop with the usual write(90) because I managed to glue the potentiometer just off of 90, somewhere between 104 and 105. so write(104) would make it turn very very slowly, and 105 would turn it the same speed the other way. But now using the writeMicroseconds method i was able to use much more detailed numbers to find a perfect stopping point. thanks all!

This little sketch might come in handy for testing:

/*
 Try this test sketch with the Servo library to see how your
 servo responds to different settings, type a position
 (0 to 180) or if you type a number greater than 200 it will be
 interpreted as microseconds(544 to 2400), in the top of serial
 monitor and hit [ENTER], start at 90 (or 1472) and work your
 way toward zero (544) 5 degrees (or 50 micros) at a time, then
 toward 180 (2400). 
*/
#include <Servo.h>
Servo servo;

void setup() {
  // initialize serial:
  Serial.begin(9600); //set serial monitor baud rate to match
  servo.write(90);
  servo.attach(9);
  prntIt();
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int pos = Serial.parseInt();
    pos = constrain(pos, 0, 2400);
    servo.write(pos);
    prntIt();
  }
}
void prntIt()
{
  Serial.print("  degrees = "); 
  Serial.print(servo.read());
  Serial.print("\t");
  Serial.print("microseconds =  ");
  Serial.println(servo.readMicroseconds());
}