hi all, below have made code model railway track use relais pull signal sending arduino switch servo position 85 95 deg change track. want detach servo after reaching position. can me , how put in detach command without loosing independent control of 6 servo's? ( deleted 3 of 6 servo's example)
i searched web didn't find working solution.
i searched web didn't find working solution.
code: [select]
#include <varspeedservo.h>
// copyright2015 - servo switch control - ssc - pauldmv
// maximum of 7 servo objects can installed on nano
// maximum of 8 servo objects can created
// change ** lines (speedx, range_x_low , range_x_high)
// install varspeedservo.h library before use!
varspeedservo myservo1; // create servo object control servo, connected pin 7
int pos1 = 0; // variable store servo position
int button1 = 1; // button on pin 1
int speed1= 2; // **variable store servo speed
int delay1= 50; // sets delay time reach position
int range_1_low= 85; // **sets lower limit
int range_1_high= 95 ; // **sets uper limit
int range_1_diff= range_1_high - range_1_low; //diffence go position
varspeedservo myservo2; // create servo object control servo, connected pin 8
int pos2 = 0; // variable store servo position
int button2 = 2; // button on pin 2
int speed2= 2; // **variable store servo speed
int delay2= 50; // sets delay time reach position
int range_2_low= 85; // **sets lower limit
int range_2_high= 95; //**sets uper limit
int range_2_diff= range_2_high - range_2_low; //diffence go position
varspeedservo myservo3; // create servo object control servo, connected pin 9
int pos3 = 0; // variable store servo position
int button3 = 3; // button on pin 3
int speed3= 2; // **variable store servo speed
int delay3= 50; // **sets delay time reach position
int range_3_low= 85; // **sets lower limit
int range_3_high= 95; //**sets uper limit
int range_3_diff= range_3_high - range_3_low; //diffence go position
void setup()
{
myservo1.attach(7); // attaches servo on pin 7 servo object
pinmode(pos1, output);
pinmode(button1, input);
digitalwrite (button1, low);
myservo2.attach(8); // attaches servo on pin 8 servo object
pinmode(pos2, output);
pinmode(button2, input);
digitalwrite (button2, low);
myservo3.attach(9); // attaches servo on pin 9 servo object
pinmode(pos3, output);
pinmode(button3, input);
digitalwrite (button3, low);
}
void loop()
{
if (digitalread(button0) == low)
for(pos0 = range_0_low; pos0 < range_0_high; pos0 += range_0_diff) // goes 85 degrees 95 degrees in steps of 1 degree
{
myservo0.slowmove(pos0,speed0); // tell servo go position in variable 'pos'
delay(delay0); // waits x ms servo reach position
}
if (digitalread(button0) == high)
for(pos0 = range_0_high; pos0>=range_0_high; pos0-=range_0_diff) // goes 95 degrees 85 degrees in steps of 1 degree
{
myservo0.slowmove(pos0,speed0); // tell servo go position in variable 'pos'
delay(delay0); // waits x ms servo reach position
}
{
if (digitalread(button1) == low)
for(pos1 = range_1_low; pos1 < range_1_high; pos1 += range_1_diff) // goes 85 degrees 95 degrees in steps of 1 degree
{
myservo1.slowmove(pos1,speed1); // tell servo go position in variable 'pos'
delay(delay1); // waits x ms servo reach position
}
if (digitalread(button1) == high)
for(pos1 = range_1_high; pos1>=range_1_high; pos1-=range_1_diff) // goes 95 degrees 85 degrees in steps of 1 degree
{
myservo1.slowmove(pos1,speed1); // tell servo go position in variable 'pos'
delay(delay1); // waits x ms servo reach position
}
{
if (digitalread(button2) == low)
for(pos2 = range_2_low; pos2 < range_2_high; pos2 += range_2_diff) // goes 85 degrees 95 degrees in steps of 1 degree
{
myservo2.slowmove(pos2,speed2); // tell servo go position in variable 'pos'
delay(delay2); // waits x ms servo reach position
}
if (digitalread(button2) == high)
for(pos2 = range_2_high; pos2>=range_2_high; pos2-=range_2_diff) // goes 95 degrees 85 degrees in steps of 1 degree
{ myservo2.slowmove(pos2,speed2); // tell servo go position in variable 'pos'
delay(delay2); // waits x ms servo reach position
}
{
if (digitalread(button3) == low)
for(pos3 = range_3_low; pos3 < range_3_high; pos3 += range_3_diff) // goes 85 degrees 95 degrees in steps of 1 degree
{
myservo3.slowmove(pos3,speed3); // tell servo go position in variable 'pos'
delay(delay3); // waits x ms servo reach position
}
if (digitalread(button3) == high)
for(pos3 = range_3_high; pos3>=range_3_high; pos3-=range_3_diff) // goes 95 degrees 85 degrees in steps of 1 degree
{
myservo3.slowmove(pos3,speed3); // tell servo go position in variable 'pos'
delay(delay3); // waits x ms servo reach position
}
}}} // 3x close bracket, 1 each servo
}
if feel enough bother detaching, guess place put after delay(delayx); have wait servo destination.
but, have ask.... why?
but, have ask.... why?
Arduino Forum > Using Arduino > Programming Questions > detach servo after reached position
arduino
Comments
Post a Comment