Go Down

Topic: Micro servo 9g program code not working (Sweep for 2) (Read 996 times) previous topic - next topic

AWOL

Code: [Select]
Servo servo2  // Again, right there.

Please remember to use code tags when posting code

Dan_L3gend

Like this?

-------------------------



#include <Servo.h>

Servo servo1;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
 servo1.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
   // in steps of 1 degree
   servo1.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
 }
 for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
   servo1.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
 }
}

Servo servo2;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
 servo2.attach(8);  // attaches the servo on pin 8 to the servo object
}

void loop() {
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
   // in steps of 1 degree
   servo2.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
 }
 for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
   servo2.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
 }
}



AWOL

Quote
Like this?
What does the compiler say?

Why have you still got two setups and two loops?

Please remember to use code tags when posting code

vinceherman

Let me help you with finding the post on How to use this forum - please read
Read all of it.  Pay attention to number 7.

In my post #7, I listed a number of steps for you to try to get this working.

The first was
Quote
Start over with the sweep example.  One setup.  One loop.
You did not do this.  Your latest code still has 2 setup functions and 2 loop functions.

Here is the code for the sweep tutorial
Code: [Select]
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}


See that it has only one setup.  And only one loop.

Try running just that, and see if you can get one servo to move.
Then try the remainder of the steps I listed in post #7.

Dan_L3gend

#19
Jun 18, 2019, 11:01 pm Last Edit: Jun 18, 2019, 11:02 pm by Dan_L3gend
It is moving, but I'm trying to sweep 2 servos at once, which isn't working from all the steps I've followed ;/

Dan_L3gend


Idahowalker

#21
Jun 19, 2019, 12:33 am Last Edit: Jun 19, 2019, 12:38 am by Idahowalker
It is moving, but I'm trying to sweep 2 servos at once, which isn't working from all the steps I've followed ;/
What mean it isn't working? Like, here at my work bench the LSM9DS1 is not working could you help me fix it? Did I give you enough information to help me get it working in the above statement?

Could you post your new code, so that we could look at it? Could you describe what you mean by it is not working?

And be patient, we are not at your beck and call.

spareProfile2


spareProfile2

"Real Helpers"

Just ditching me...
Thing about forums is, they're 24/7 over all the time zones. Perhaps the one who was helping you went to bed, or is driving his car, or went into a meeting at work, or went to the beach, or is reading a book or (imagine this) working on his own Arduino stuff for a while. Forums aren't help-desks where you open a docket and a support person is assigned to your case until it's resolved.





slipstick

"Real Helpers"

Just ditching me...
So far you've ignored everything I said and almost everything the others have told you.

There's only so long we can keep trying if you won't actually take any help. And yes this reply is late. I went to bed. You're not paying any of us nearly enough to keep us up all night.

Steve

vinceherman

Who is ditching who?

You have been asked multiple times to post your code.  Your latest attempt has no code attached.
You have been asked multiple times to read and follow the guidelines in the "How to use this forum - please read" post.

You have a number of people on here trying to help you.  Don't get an attitude because we are not meeting your expectations.

Still want help?
Read the "How to use this forum - please read" post.
Post your code.  Use code tags.
Describe what you expected the sketch to do and what the sketch actually did.

Go Up