Tutorial.Sweep History

Show minor edits - Show changes to markup

November 13, 2012, at 10:43 AM by Roberto Guido - corrected link for map(). Thanks Matt Rodriguez for the alert
Changed lines 46-47 from:
to:
November 16, 2011, at 04:39 AM by Scott Fitzgerald -
Changed lines 40-41 from:
to:
September 24, 2010, at 05:49 AM by Tom Igoe -
Changed lines 40-70 from:
to:
September 23, 2010, at 10:53 PM by Christian Cerrito -
Changed lines 3-4 from:

Sweep

to:

Sweep

September 20, 2010, at 04:01 PM by Christian Cerrito -
Changed lines 5-6 from:

Sweeps the shaft of a servo motor back and forth.

to:

Sweeps the shaft of a RC servo motor back and forth across 180 degrees.

This example makes use of the Arduino servo library.

September 20, 2010, at 03:55 PM by Christian Cerrito -
Added lines 77-78:
September 20, 2010, at 03:55 PM by Christian Cerrito -
Changed lines 71-76 from:
to:
September 20, 2010, at 03:52 PM by Christian Cerrito -
Changed lines 36-37 from:

Code

to:

Code

September 20, 2010, at 03:50 PM by Christian Cerrito -
Deleted lines 4-5:

Description

Changed lines 7-8 from:

Circuit

to:
Added lines 20-35:
Changed lines 38-39 from:

[@

to:
Changed lines 67-68 from:

@]

to:
October 17, 2008, at 05:29 PM by Paul Badger -
Changed lines 11-12 from:

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow or orange and should be connected to pin 9 on the Arduino board.

to:

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and should be connected to pin 9 on the Arduino board.

October 12, 2008, at 12:02 AM by David A. Mellis -
Changed lines 22-23 from:
                // a maximum of eight servo objects can be created 
to:

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

Deleted lines 24-25:

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

Deleted line 29:
October 11, 2008, at 11:59 PM by David A. Mellis -
Added lines 1-49:

Examples > Servo Library

Sweep

Description

Sweeps the shaft of a servo motor back and forth.

Circuit

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow or orange and should be connected to pin 9 on the Arduino board.

Code

// Sweep
// by BARRAGAN <http://barraganstudio.com> 

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 

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>=1; 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 also

Share