Servo motor programming

what does "#include <Servo.h>" do in the programming. I think it may be a library to make it easier to move a servo. I refer particularly to this sketch;

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

int val;    // set val between 0-180 to move servo


void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  
  Serial.begin(115200);
}
void loop() {
Serial.print("input value for variable val: ");

while (Serial.available() == 0) {
  }
val = Serial.parseInt();
Serial.print("val=");
Serial.println(val);
 myservo.write(val);                 
  delay(15);
                            
}

You are correct.

The library defines the functions you will use to control the "myservo" object.

That is correct. Degrees are easily human readable, so someone wrote this library that will convert degrees into the necessary pulses required to move the servo.

Here is the same question with some very good responses and links:

https://forum.arduino.cc/t/servo-h-where-can-i-get-the-detail/1104627/2

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.