Delay Motor Problem & Controlling 2 Motors are different speed.
hello,
i have problem servo motor. using arduino uno, , towerpro mg995 servo motor. motor starter kit. using sweep example code arduino , reason when changed delay 15ms 1000ms, servo no longer runs 0 180 , reverse. goes angle , gets stuck @ point. changed delay in code , nothing else.
here code:
// sweep
// barragan <http://barraganstudio.com>
// example code in public domain.
#include <servo.h>
servo myservo; // create servo object control servo
// maximum of 8 servo objects can created
int pos = 0; // variable store servo position
void setup()
{
myservo.attach(9); // attaches servo on pin 9 servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes 0 degrees 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo go position in variable 'pos'
delay(15); // waits 15ms servo reach position
}
for(pos = 180; pos>=1; pos-=1) // goes 180 degrees 0 degrees
{
myservo.write(pos); // tell servo go position in variable 'pos'
delay(15); // waits 15ms servo reach position
}
}
in code changed delay(15) delay(1000).
also, wondering how can change code make 2 motors run @ different speeds. code after awhile start run @ same speed. not want. want myservo1 run 20 degrees ahead of myservo2 every position (degree). here code:
#include <servo.h>
servo myservo0, myservo1;
int pos = 0;
void setup()
{
myservo0.attach(9);
myservo1.attach( 8 );
}//setup
void loop()
{
for(pos = 0; pos < 180; pos += 1)
{
myservo0.write(pos);
myservo1.write(pos + 20);
delay(10);
}//for
for(pos = 180; pos >= 1; pos -= 1)
{
myservo0.write(pos);
myservo1.write(pos + 20);
delay(10);
}//for
}//loop
i have problem servo motor. using arduino uno, , towerpro mg995 servo motor. motor starter kit. using sweep example code arduino , reason when changed delay 15ms 1000ms, servo no longer runs 0 180 , reverse. goes angle , gets stuck @ point. changed delay in code , nothing else.
here code:
// sweep
// barragan <http://barraganstudio.com>
// example code in public domain.
#include <servo.h>
servo myservo; // create servo object control servo
// maximum of 8 servo objects can created
int pos = 0; // variable store servo position
void setup()
{
myservo.attach(9); // attaches servo on pin 9 servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes 0 degrees 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo go position in variable 'pos'
delay(15); // waits 15ms servo reach position
}
for(pos = 180; pos>=1; pos-=1) // goes 180 degrees 0 degrees
{
myservo.write(pos); // tell servo go position in variable 'pos'
delay(15); // waits 15ms servo reach position
}
}
in code changed delay(15) delay(1000).
also, wondering how can change code make 2 motors run @ different speeds. code after awhile start run @ same speed. not want. want myservo1 run 20 degrees ahead of myservo2 every position (degree). here code:
#include <servo.h>
servo myservo0, myservo1;
int pos = 0;
void setup()
{
myservo0.attach(9);
myservo1.attach( 8 );
}//setup
void loop()
{
for(pos = 0; pos < 180; pos += 1)
{
myservo0.write(pos);
myservo1.write(pos + 20);
delay(10);
}//for
for(pos = 180; pos >= 1; pos -= 1)
{
myservo0.write(pos);
myservo1.write(pos + 20);
delay(10);
}//for
}//loop
take both delays out of loops , put them right after loops.
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Delay Motor Problem & Controlling 2 Motors are different speed.
arduino
Comments
Post a Comment