What would the code look like to simply have a servo just continuously spin
You need a modified servo to spin continuously. There are instructions various places on the internet.
Here's one: Dios — Kronos Robotics
(note that there are two common types of "continuous rotation" modification for servos. In one, all the servo electronics are removed, turning the servo into a gear-motor that has to be controlled with a relatively high-power motor driver. The other (as in the link above) leaves the electronics intact so that the motor can be controlled by a logic signal, but removes mechanical feedback so that the electronics can no longer figure out what the motor position is, and just keeps trying to reach it.)
And here's a message about driving such a modified servo from an Arduino:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251100597
(hmm. Haven't tried it was the newer servo library...)
I have it spinning
Here is my code but I would like it to go slower
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
}
void loop()
{
myservo.write(1500);
}
Here is a test sketch you can use to check for the values to set the desired speed. Connect a pot to analog pin 1 (see: http://www.arduino.cc/en/Tutorial/AnalogInput) and note the values printed on the serial monitor as the speed changes. Writing this value to the servo will set that speed.
#include <Servo.h>
// connect center pin of a pot to analog input 0
// connect outer pot pins to +5V and Gnd.
// for more on how to wire, see: http://www.arduino.cc/en/Tutorial/AnalogInput
Servo myservo; // create servo object to control a servo
int sensorPin = 0; // select the input pin for the potentiometer
int stopped = 90; // tweak this to a value that results in no servo rotation
int pos = stopped; // variable to store the servo position
int oldPos; // used so that only new (changed) values are printed
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop()
{
// read the value from the sensor:
int sensorValue = analogRead(sensorPin);
pos = map(sensorValue, 0,1023, 0, 180);
myservo.write(pos);
if(oldPos != pos) {
Serial.println(pos); // only print when pos changes
oldPos = pos;
}
delay(100);
}
note that the latest servo library will work in degrees or microseconds, this code uses degrees