Search code examples
arduinoadafruitservo

Is there a way to write the servo position in angles with Adafruit 1411 Servo shield?


I'm trying to control my 180 degree servo motors through a Adafruit 1411 Servo shield. However I don't find it simple enough to write the servo's position in angles like the normal servo library without the shield.

Using the Adafruit 1411 Servo shield and Adafruit_PWMServoDriver-library lets you control a servomotor by modifying its pulselength as far as I've realised. To my question..

Is there a way for me to either use the servo shield's output and still write in degrees OR somehow convert these pulselength into angle-degree?

Example of the differences:

Adafruit_PWMServoDriver-library:

pwm.setPWM(Servo, 0, pulseLength);

Servo-library:

Servo.write(45); //Writing in angles like this would be optimal for my project.

Any help in the right direction is much appreciated!


Solution

  • Use the Arduino map function. The following is from the Adafruit instructions:

    pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
    

    Where SERVOMIN and SERVOMAX are values you set according to the range of travel of your servo. This linearly maps a value between 0 and 180 into the range between SERVOMIN and SERVOMAX.

    Since you've been doing this with pulse widths so far, you probably already knew the values you need to use.