Yes I do indeed mean servos. Lame old cheap 180 degree servos. I know they are not the most precise, or in any way the most reliable motors out there - at the moment I'm really just out to build a proof of concept but I can't adjust the code accordingly.
I'm not entirely sure how but I am definitely able to adjust the speed of the servos...Maybe it has to do with altering the frequency of the internal loop?
It would probably make more sense if I showed you the code I already have:
1st Tab:
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
#define roll 0
#define pitch 1
#define yaw 2
#define Boo 3
#define UP 1
#define DOWN 0
#define HOLD 2
Servo servo[4]; // create servo object to control a servo
int direct[4] = {0,0,0,0};
int steps[4];
int pos[4] = {0,0,0,0};
int target[4];
int hold[4];
int maxCount[4];
int minCount[4];
long servoMin[4];
long servoMax[4];
long servoPauseMin[4];
long servoPauseMax[4];
long servoSpeed[4];
long previousMillis[4] = {0,0,0,0}; // will store last time LED was updated
unsigned long currentMillis[4];
long interval = 4000; // interval at which to blink (milliseconds)
2nd Tab - Drive:
void drive(int servos, int minTarget, int maxTarget,int minHold, int maxHold, int speeds) {
if(direct[servos] == UP){
if (pos[servos] < maxTarget){
pos[servos] = pos[servos] + speeds ;
}
else if (pos[servos] >= maxTarget){
maxCount[servos]++;
if(maxCount[servos] >= maxHold){
maxCount[servos] = 0;
direct[servos] = DOWN;
}
}
}
if(direct[servos] == DOWN){
if(pos[servos] > minTarget){
pos[servos] = pos[servos] - speeds ;
}
else if (pos[servos] <= minTarget){
minCount[servos]++;
if(minCount[servos] >= minHold){
minCount[servos] = 0;
direct[servos] = UP;
Serial.print("........................................................" );
}
}
}
/*
Serial.print("\t servo" );
Serial.print(servos);
Serial.print(" = ");
Serial.print(pos[servos]);
Serial.print(" ");
Serial.print(minTarget);
Serial.print(" ");
Serial.print(maxTarget);
Serial.print("\t direction = " );
Serial.println(direct[servos]);
//if(servos == 2) Serial.println();
*/
servo[servos].write(pos[servos]);
delay(15);
}
3rd Tab - Loop:
void loop() { //(servo, its minimum target, maximum target, pause at the min position, pause at max position, its speed)
// servo[pitch].write(80); //pitch range = 20 - 80
//servo[roll].write(120); //roll range = 100 - 130
servoMin[roll] = 0;
servoMax[roll]= 180;
servoPauseMin[roll] = 0;
servoPauseMax[roll] = 0;
servoSpeed[roll]= 1;
servoMin[pitch]= 0;
servoMax[pitch] = 180;
servoPauseMin[pitch]= 0;
servoPauseMax[pitch]= 0;
servoSpeed[pitch]= 2;
servoMin[yaw]= 0;
servoMax[yaw] = 180;
servoPauseMin[yaw]= 0;
servoPauseMax[yaw]= 0;
servoSpeed[yaw]= 2;
servoMin[Boo]= 0;
servoMax[Boo] = 180 ;
servoPauseMin[Boo]= 0;
servoPauseMax[Boo]= 0;
servoSpeed[Boo]= 1;
/*
servoMin[roll] = random(0, 100);
servoMax[roll]= random(servoMin[roll], 180);
servoPauseMin[roll] = random(0, 2000);
servoPauseMax[roll] = random(0, 2000);
servoSpeed[roll]= random(0, 5);
servoMin[pitch]= random(0, 100);
servoMax[pitch] = random(servoMin[pitch], 180);
servoPauseMin[pitch]= random(0, 2000);
servoPauseMax[pitch]= random(0, 2000);
servoSpeed[pitch]= random(0, 5);
servoMin[yaw]= random(0, 100);
servoMax[yaw] = random(servoMin[yaw], 180);
servoPauseMin[yaw]= random(0, 1000);
servoPauseMax[yaw]= random(0, 1000);
servoSpeed[yaw]= random(0, 5);
*/
drive(roll,servoMin[roll],servoMax[roll],servoPauseMin[roll], servoPauseMax[roll],servoSpeed[roll]);
drive(pitch, servoMin[pitch],servoMax[pitch],servoPauseMin[pitch],servoPauseMax[pitch],servoSpeed[pitch]);
drive(yaw,servoMin[yaw],servoMax[yaw],servoPauseMin[yaw],servoPauseMax[yaw],servoSpeed[yaw]);
drive(Boo,servoMin[Boo],servoMax[Boo],servoPauseMin[Boo],servoPauseMax[Boo],servoSpeed[Boo]);
//drive(roll,180,0,1000,1000,1);
// drive(pitch,180,0,1000,1000,4);
//drive(yaw,180,0,1000,1000,2);
}
4th Tab - Setup:
void setup() {
randomSeed(analogRead(0));
Serial.begin(9600);
servo[roll].attach(2); // attaches the servo on pin 9 to the servo object
servo[pitch].attach(3); // attaches the servo on pin 9 to the servo object
servo[yaw].attach(4); // attaches the servo on pin 9 to the servo object
servo[Boo].attach(5); // attaches the servo on pin 9 to the servo object
pos[roll] = 90;
pos[pitch] = 90;
pos[yaw] = 90;
pos[Boo] = 90;
}