Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Programs >> Pause in servo-program
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1261298640

Message started by Jack on 12/20/09 at 08:44:00

Title: Pause in servo-program
Post by Jack on 12/20/09 at 08:44:00
Hallo,
I want 2 pauzes in the next program.(delay(1500);
But it is not working! What is wrong?
Thanks for any help.
      Jack
/**
* Driving Servo
* by BARRAGAN <http://barraganstudio.com>
*
* Demonstrates the use of the servo library, it sweeps a generic
* servo motor from the minimum to the maximum position
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(0);  // attaches the servo on pin 0 to the servo object
}


void loop()
{
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
 
     delay(1500);   
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
   {
     delay(1500);
   } 
}

Title: Re: Pause in servo-program
Post by Vaccumdiode2 on 12/21/09 at 19:08:14
Hello Jack,

           Could you tell us what it is doing and what it is not doing? 

            Does the servo move?  Does the program lock up?

            I Noticed that you had brackets around your second delay(1500). You Should remove them. They are not needed and it may the root of the problem.

             Also please decribe what you are trying to do.  If you want it to delay after every movement then the delay in the for loop should be increased.  change delay(15) to delay(1500).

Thank you,

Vaccumdiode


Title: Re: Pause in servo-program
Post by Jack on 12/22/09 at 17:19:01
Thanks for the comment.
The servo move correct, but i want after each movement
the servo stops for say 1.5 sec.
The command delay(1500) does not work.
   Jack.

Title: Re: Pause in servo-program
Post by Vaccumdiode2 on 12/22/09 at 18:11:26
Jack,
              Change the delay in each of the "for loop" to delay(1500) from delay(15).  Then completely remove both of the delay(1500) you put in. 
               Every cycle of the "for loop" the servo changes position.  so the exteded delay needs to be put in the "for loop".



for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);    // tell servo to go to position in variable 'pos'
    delay(1500);         // waits 1500ms for the servo to reach the position
  }
 
     delay(1500);   
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);    // tell servo to go to position in variable 'pos'
    delay(1500);          // waits 1500ms for the servo to reach the position
  }

I hope I understood you correctly.  this should do what you want.

Please let me know if this helped.

Vaccumdiode

Title: Re: Pause in servo-program
Post by Jack on 12/23/09 at 13:14:58
No, is not working.
The servo begins rotating left and is stil running (endles) to
the left.

Title: Re: Pause in servo-program
Post by Vaccumdiode2 on 12/23/09 at 14:32:06
Jack,
         Please double check your wire conections.  I have been doing electronics for 37 years and I hook things wrong and don't see then and it drive nuts still.   The fact that it keeps turning could indicate wire conection problems. 

       Remember some servo return to it's home position automaticly.  Please let me know what type of servo and the colors of the wires.  There is not a standard for wire color or pin position for servos.

Try this as a test.

#include <Servo.h>

Servo myservo0;  // create servo object to control a servo

void setup()
{
  myservo0.attach(0);  // attaches the servo on pin 0 to the servo object
}


void loop()
{
  myservo0.write(0);    // position first servo at 0 degrees
 
  delay(1000);          // wait for the servos to reach the desired position

  myservo0.write(90);   // at 90 degrees

delay(500);            

myservo0.write(180);  // at 180 degrees

  delay(500);                     
}

Please let me know how it goes. 

Vaccumdiode

Title: Re: Pause in servo-program
Post by Jack on 12/23/09 at 21:03:45
Hallo Vaccumdiode,
the servo turns 90 degrees right and afterthat 180 degrees left enso on.
Jack.

Title: Re: Pause in servo-program
Post by Vaccumdiode2 on 12/30/09 at 13:39:58
Jack,
          Sorry for the delay in getting back to you.  The Holidays had me running around.
      
           The first thing the test program should do is return to home position ( 0 degrees)  then turn ( 90 degrees) and then turn (180 degrees ) then repeat the loop. 


Try increasing the delays to 1500 on each one.  I think the servo is moving slow and the program  loop is moving much faster.  It is stop for the 90 degree position before it physically reaches the position.

Keep me informed.

Vaccumdiode

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.