Continuous Rotation Servos
Code
// Program for using continuous rotation servos
//1500 = stop, 2000 full speed counter clockwise, 1000 full speed clockwise
//***************WIRING GUIDE**********************
//attach red wire of servo to 5V
//attach black/brown wire of servo to ground
//attach yellow/white wire of servo to pin 10
#include <Servo.h> //this adds code to our program that defines what a Servo object is and can do
Servo amotor; // create a servo object to control a servo
int mspeed = 1500; // variable to store the motor speed
void setup() {
amotor.attach(10); // attaches the servo on pin 10 to the servo object amotor
}
void loop(){
// Run Motor full speed clockwise for 1 second
mspeed = 1000; //set position variable
amotor.writeMicroseconds(mspeed); // tell servo to move as indicated by variable 'mspeed'
delay(1000); //time for the servo to move
// Run Motor full speed counter clockwise for 1 second
mspeed = 2000; //set position variable
amotor.writeMicroseconds(mspeed); // tell servo to move as indicated by variable 'mspeed'
delay(1000); //time for the servo to move
//Stop Motor for one second
mspeed = 1500; //set position variable
amotor.writeMicroseconds(mspeed); // tell servo to move as indicated by variable 'mspeed'
delay(1000); //time for the servo to move
}
//1500 = stop, 2000 full speed counter clockwise, 1000 full speed clockwise
//***************WIRING GUIDE**********************
//attach red wire of servo to 5V
//attach black/brown wire of servo to ground
//attach yellow/white wire of servo to pin 10
#include <Servo.h> //this adds code to our program that defines what a Servo object is and can do
Servo amotor; // create a servo object to control a servo
int mspeed = 1500; // variable to store the motor speed
void setup() {
amotor.attach(10); // attaches the servo on pin 10 to the servo object amotor
}
void loop(){
// Run Motor full speed clockwise for 1 second
mspeed = 1000; //set position variable
amotor.writeMicroseconds(mspeed); // tell servo to move as indicated by variable 'mspeed'
delay(1000); //time for the servo to move
// Run Motor full speed counter clockwise for 1 second
mspeed = 2000; //set position variable
amotor.writeMicroseconds(mspeed); // tell servo to move as indicated by variable 'mspeed'
delay(1000); //time for the servo to move
//Stop Motor for one second
mspeed = 1500; //set position variable
amotor.writeMicroseconds(mspeed); // tell servo to move as indicated by variable 'mspeed'
delay(1000); //time for the servo to move
}