I'm using the sketch below to experiment with the 'SG90 micro servo' that came with my starter kit.
Q1: With the values shown I would expect to get a 180 degree sweep in both directions, but I estimate it as about 150. Trying other values, it always falls short by20-30 degrees. Is that normal?
Q2: Is there a sketch available anywhere that uses a function, with parameters (such as start and finish angle, and duration)? That might be neater and easier to use for testing.
Q3: For the project I have in mind I will probably need a servo with greater torque but still compact in size. Any recommendations before I start googling please?
Q4: On a general point, why are comments inside /* always in a faint, hard-to-read font? Can that be changed?
Any other practical advice would be appreciated please.
Terry, UK
Q1: With the values shown I would expect to get a 180 degree sweep in both directions, but I estimate it as about 150. Trying other values, it always falls short by20-30 degrees. Is that normal?
Q2: Is there a sketch available anywhere that uses a function, with parameters (such as start and finish angle, and duration)? That might be neater and easier to use for testing.
Q3: For the project I have in mind I will probably need a servo with greater torque but still compact in size. Any recommendations before I start googling please?
Q4: On a general point, why are comments inside /* always in a faint, hard-to-read font? Can that be changed?
Any other practical advice would be appreciated please.
Code:
//www.elegoo.com
//2016.12.08
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 10; pos <= 180; pos += 1)
{ // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
delay(500);
for (pos <= 180; pos = 10; pos -= 1)
{ // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
delay(1000);
}