Go Down

Topic: Making two servos rotate in opposite directions (Read 881 times) previous topic - next topic

katkatkattkac

Hello!
Just a quick question, and there may be an easy answer to it, but I can't figure it out. I have two servos, and both of them are rotating 180 in the same direction. How do I get them to rotate in opposite directions? Here is my code:


Code: [Select]

#include <Servo.h>

Servo myservo;
Servo myservoe;

int pos = 0;   

void setup() {
  myservo.attach(9);
  myservoe.attach(6);
  #include <Servo.h>
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) {
    // in steps of 1 degree
    myservo.write(pos);             
    delay(5);
    myservoe.write(pos);
    delay(100);//
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);             
    delay(5); 
    myservoe.write(pos);
    delay(100);
  }
}

AWOL

Code: [Select]
myservo.write(pos);             
    delay(5);
    myservoe.write(180 - pos);
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy