I am interested in writing a simple Arduino program that will turn a servo back and forth (180 degrees each time) continuously.
I am looking at these servos and am planning on following this example.
Being so new to Arduino, I first wanted to confirm that the SoftwareServo
library in that example will drive those particular servos. If it will not, then can someone begin by explaining to me why these servos are incompatible with the lib?
Assuming they are compatible, I am looking at the main example on that page (comments stripped out for brevity):
#include <SoftwareServo.h>
SoftwareServo myservo;
int potpin = 0;
int val;
void setup() {
myservo.attach(2);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
myservo.write(val);
delay(15);
SoftwareServo::refresh();
}
My concerns:
- There seem to be 3 pins involved here: a potentiometer pin (
0
), an analog pin (val
) and a servo pin (2
). What is the purpose of each of these pins, and is this 3-pin wiring common across all/most servos? - Is there anything "wrong" with defining
myservo.attach(2);
up above thesetup
function, and leave thesetup
function an empty no-op function? - Where does the
map(...)
function come from? If it was defined insideSoftwareServo
I would have expected its usage to be something likeSoftwareServo::map(...)
, etc. - Why do we need the
delay
after callingmyservo.write(val);
? What would happen if this delay wasn't in there? - According to that link, calling
SoftwareServo::refresh()
once every 50ms is necessary in order to: "keep your servos updating." But what does this mean, really? Updating to what?!?