Go Down

Topic: Making two servos rotate in opposite directions (Read 1 time) 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