SHED-Article2SOFTWARE - ServoSweep

From ArduinoInfo
Jump to navigation Jump to search

SHED-Article2SOFTWARE - ServoSweep


CONNECTIONS:

  • Servo connector plugged on YourDuinoRobo1 port 9 (MATCH colors)
  • If separate wires:
    • Servo Black to Gnd.
    • Servo Red or Orange (Center wire) to +5V
    • Servo White or Yellow to Signal (Pin 9)


(Copy the text in the box below and Paste it into a blank Arduino IDE window)

/* SHED Magazine Arduino Sketch Servo Sweep
 - Moves a Servomotor through a range of positions
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
 - Servo connector plugged on YourDuinoRobo1 port 9
 - If separate wires:
  - Servo Black to Gnd.
  - Servo Red or Orange (Center wire) to +5V
  - Servo White or Yellow to Signal (Pin 9)
 - V1.01 09/13/12
 Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Servo.h>  // Comes with Arduino IDE

/*-----( Declare Constants and Pin Numbers )-----*/
#define ServoPIN  9  // Can be changed 3,5,6,9,10,11
#define ServoMIN  20 // Don't go to end of servo travel
#define ServoMAX  160 // which may be 0 to 180. 

/*-----( Declare objects )-----*/
Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created

/*-----( Declare Variables )-----*/
int pos = 0;    // variable to store the servo position 


void setup()   /****** SETUP: RUNS ONCE ******/
{
  myservo.attach(ServoPIN);  // attaches the servo on pin 9 to the servo object 

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  for(pos = ServoMIN; pos < ServoMAX; 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 
  }
  delay(1000);
  for(pos = ServoMAX; pos>=ServoMIN; 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 
  }
  delay(2500);

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
//none

//*********( THE END )***********






HTML for above Sketch:
[/file/view/ServoPot.html/367923548/ServoPot.html ServoPot.html]
[/file/view/ServoPot.html/367923548/ServoPot.html ServoPot.html]
  • [/file/detail/ServoPot.html Details]
  • [/file/view/ServoPot.html/367923548/ServoPot.html Download]
  • 5 KB