Go Down

Topic: Servo help for quadruped! (Read 646 times) previous topic - next topic

Steven33

I built a quadruped and I'm having troubles making it move correctly. I have successfully made it go in a circle but not straight. I am using Arduinos servo library and I just need to know something. How do I make 2 servos sweep at the same time in opposite directions. I can use a for statement and make 2 sweep in the same direction, but that not what I need.  :-\ 

PaulS

#1
Apr 07, 2018, 03:10 am Last Edit: Apr 07, 2018, 02:04 pm by AWOL
Quote
How do I make 2 servos sweep at the same time in opposite directions.
Pretty simple, really. If you want one to go from 90 to 0, and the other to go from 0 to 90, it is not that difficult to see that if the loop index goes from 0 to 90, one servo follows the loop index, and the other follows 90 minus the loop index.
The art of getting good answers lies in asking good questions.

Steven33

can you show me example code for that. I'm new to programing

slipstick

Read the "How to use this forum" sticky at the top of the forum that tells you how to post code correctly in</> code tags.

Then use your new knowledge to show us your current code that sweeps 2 servos together and we'll fix it to sweep in opposite directions. But it's often as simple as - if you're now doing write(x) to both servos you need to change one of them to write(180-x).

Steve

PaulS

can you show me example code for that. I'm new to programing
Code: [Select]
for(byte pos = 0; pos<90; pos++)
{
   oneServo.write(pos);
   twoServo.write(90-pos);
}


Like I said, not exactly rocket science.
The art of getting good answers lies in asking good questions.

Steven33

well sorry, I litterally just started programming and thanks  :)

Go Up