Go Down

Topic: Motor Troubles (Read 73 times) previous topic - next topic

bubbles

Hi, my name is Bubbles, and I'm having trouble with some motor control.  I want to activate multiple motors at once (5 to be exact) and they all seem to go one by one.  I have removed any and all delays.  I want the code to run only once and have all 5 motors run at once.  Do you have any tips?

-Please respond as quickly as possible, this is for a time sensitive project.
Thanks,
Bubbles

bubbles

#include <Servo.h>

Servo myservo1, myservo2, myservo3, myservo4, myservo5;

int pos = 0;   

void setup() {
  myservo1.attach(9);
  myservo2.attach(8)
  myservo3.attach(7); 
  myservo4.attach(6); 
  myservo5.attach(5); 
}

void loop() {

  for (pos = 0; pos <= 180; pos += 2) {
    // in steps of 2 degrees
    myservo1.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos -= 2) {
     myservo1.write(pos);             
     delay(15);                       
  myservo1.detach();
  }
  for (pos = 0; pos <= 180; pos += 2) {
    // in steps of 2 degrees
    myservo2.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos -= 2) {
     myservo2.write(pos);             
     delay(15);                       
  myservo2.detach();
  }
  for (pos = 0; pos <= 180; pos += 2) {
    // in steps of 2 degrees
    myservo3.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos -= 2) {
     myservo3.write(pos);             
     delay(15);                       
  myservo3.detach();
  }
  for (pos = 0; pos <= 180; pos += 2) {
    // in steps of 2 degrees
    myservo4.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos -= 2) {
     myservo4.write(pos);             
     delay(15);                       
  myservo4.detach();
  }
  for (pos = 0; pos <= 180; pos += 2) {
    // in steps of 2 degrees
    myservo5.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos -= 2) {
     myservo5.write(pos);             
     delay(15);                       
  myservo5.detach();
  }
}


This is the code I'm having troubles with

bubbles

Sorry, I just realized there was an emoji in place of the number eight.

-Bubbles

PaulS

Quote
Do you have any tips?
Learn to post code properly. There is a sticky at the top of every forum that explains how.
Learn NOT to hijack other people's threads.

Quote
Please respond as quickly as possible, this is for a time sensitive project.
Learn to start working on assignments early enough to be able to complete them even if you encounter issues.

Quote
I'm having trouble with some motor control.
Learn to properly express yourself. "I'm having problems" doesn't tell us squat. "The 4th servo moves in the wrong direction" tells us a whole lot more.

Quote
I have removed any and all delays.
You seem to have missed a few.

Code: [Select]
   for (pos = 180; pos >= 0; pos -= 2) {
     myservo1.write(pos);             
     delay(15);                       
  myservo1.detach();
  }

Move the servo to position 180. Wait 15 milliseconds. Detach the servo. Immediately, move the detached servo to position 178. How do you expect that THAT is going to work?
The art of getting good answers lies in asking good questions.

Go Up