I am trying to control multiple servo's with its position and velocity. But i am not getting how to use the var speed library to control the velocity of the motors also. Currentely i'm trying below program without any success.
/*
ServoSequence
Reads an analog input, and plays different servo sequences depending on the analog value
This example code is in the public domain.
*/
#include <VarSpeedServo.h>
VarSpeedServo myservo1, myservo2, myservo3;
const int servoPin1 = 6; // the digital pin used for the servo
// sequences are defined as an array of points in the sequence
// each point has a position from 0 - 180, and a speed to get to that position
servoSequencePoint slow[] = {{100,20},{20,20},{60,50}};
servoSequencePoint twitchy[] = {{0,255},{180,40},{90,127}};
const int analogPin = A0;
// the setup routine runs once when you press reset:
void setup() {
myservo1.attach(servoPin1);
myservo2.attach(8);
myservo3.attach(5);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(analogPin);
if (sensorValue > 200) {
myservo1.sequencePlay(slow, 3); // play sequence "slowHalf" that has 3 positions, loop and start at first position
myservo2.sequencePlay(slow,3);
} else {
myservo1.sequencePlay(slow, 3); // play sequence "slowHalf" that has 3 positions, loop and start at first position
myservo2.sequencePlay(slow,3);
}
delay(2); // delay in between reads for analogin stability
}
Here whenever i assign the slow list value inside the loop than it don't works. It seems like its value has to be declared globally, than only it works. How can i assign the servosequencePoint value inside the loop, so that each time i can change the parameters and than move the servo in different order?
I also tried to modify the SweepTwoServo example from the VarSpeedServo library, but seems like i can't use it for more than two servo, so i'm trying this servoSequence program. But i'm not being able to modify it further to make it work properly.