#include <Servo.h>
Servo servo_7;
void setup()
{
servo_7.attach(7);
}
void loop()
{
servo_7.write(45);
delay(10);
}
/* servo connected to pin 7 will maintain an angle of 45o */
]] ></ac:plain-text-body></ac:structured-macro><p><br /></p><p><br /></p><p><ac:image ac:height="250"><ri:attachment ri:filename="image2019-12-28_18-47-48.png" /></ac:image></p><p>Caution : Do not overload the servo. The servo and your battery / power source could be damaged if servo is overloaded.</p><p>Do not power the servo from a 9V battery. Most servos can’t take > 6V.</p><p><br /></p><p><strong>Exercise 6</strong></p><ul><li>Create a program to sweep the servo back and forth between 0o and 180o gradually such that it takes a total of 18 seconds to complete a back and forth sweep</li></ul><p>Hint :</p><ul><li>Increment and decrement by 1o, with a 50 milliseconds delay at each step</li></ul>ul><p><br /></p><ac:structured-macro ac:name="code" ac:schema-version="1" ac:macro-id="41ef3738-d59b-4b15-8e05-4a8f467ff94c"><ac:parameter ac:name="language">cpp</ac:parameter><ac:plain-text-body><![CDATA[#include <Servo.h>
Servo myservo;
int pos = 0;
// variable to store the servo position
void setup()
{
myservo.attach(7);
}
void loop()
{
for(pos = 0; pos <= 180; pos++)
{
myservo.write(pos);
delay(50);
}
for(pos = 180; pos >= 0; pos--)
{
myservo.write(pos);
delay(50);
}
}
]] ></ac:plain-text-body></ac:structured-macro> |