How to screw with the sweep arduino code for your own personal use

This example code is in the public domain.
 modified 8 Nov 2013

 by Scott Fitzgerald

 http://www.arduino.cc/en/Tutorial/Sweep

*/
#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

  }

}

So from this code here is how to work:

If you wish to modify the amount it turns look at the code here:

  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

What you see is a code that tells the servo motor to go in a 180 degree spin. What you need to do is to determine the personalized angle at which you wish to turn and enter it in from the 180.

    delay(15); // waits 15ms for the servo to reach the position

The type of code that needs to devised is the delay(15) which basically means it would take 15 Milliseconds for the servo to reach its position. 

So you should understand that 15 milliseconds is 0.015 seconds. Which means that it would take 0.015 seconds to reach 1 degree.

2.7 seconds in order to reach the whole 180 degrees.

A lot of this would have to be your own math so remember:

((Delay(15) x 180))/1000 = per second 

That should be the formula for the timing of your arduino sweep

  

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s