0% found this document useful (0 votes)
2 views1 page

Servo Motor Code

This C++ code controls a servo motor using the Servo library. It initializes the servo on pin 9 and continuously moves it from 0 to 360 degrees and back. The loop includes a delay to control the speed of the servo movement.

Uploaded by

Kaye Bolima
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Servo Motor Code

This C++ code controls a servo motor using the Servo library. It initializes the servo on pin 9 and continuously moves it from 0 to 360 degrees and back. The loop includes a delay to control the speed of the servo movement.

Uploaded by

Kaye Bolima
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// C++ code

//
#include <Servo.h>
int pos = 0;
Servo servo_9;

void setup()
{
servo_9.attach(9, 500, 2500);
}
void loop()
{
for (pos = 0; pos <= 360; pos += 1) {
servo_9.write(pos);
}
for (pos = 360; pos >= 0; pos -= 1) {
servo_9.write(pos);
delay(15);
}
}

You might also like