Test program Sweep and Tilt

Test program for the Pan and tilt unit. Sets the unit to sweep back and forth through 180 degrees with an up and down tilt scan at the limit of each sweep.

// Modified from Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
// by David Baxter 3 November 2014

#include <Servo.h>   // loads the arduino Servo library
Servo myservo_tilt, myservo_pan;  // create servo object to control a servo

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

void setup()
{
myservo_tilt.attach(3);  // attaches the servo on pin 3 to the tilt servo object
myservo_pan.attach(2);   // attaches the servo on pin 2 to the pan servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees PANS ROUND
{                                  // in steps of 1 degree
myservo_pan.write(pos);              // tell servo to go to position in variable ‘pos’
delay(15);                       // waits 15ms for the servo to reach the position
}
for(pos = 90; pos < 180; pos += 1)  //  AT LIMIT OF PAN TILTS UP AND DOWN
{                                  // tilts up from 90 degrees to 180 degrees in steps of 1 degree
myservo_tilt.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>=90; pos-=1)     // tilts down from 180 degrees to 90 degrees
{
myservo_tilt.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)     //  PANS BACK ROUND
{
myservo_pan.write(pos);              // goes from 180 degrees to 0 degrees tell servo to go to position in variable ‘pos’
delay(15);                       // waits 15ms for the servo to reach the position
}
for(pos = 90; pos < 180; pos += 1)  //  AT LIMIT TILTS UP AND DOWN
{                                  // tilts up from 90 degrees to 180 degrees in steps of 1 degree
myservo_tilt.write(pos);
delay(15);
}
for(pos = 180; pos>=90; pos-=1)     // tilts down from 180 degrees to 90 degrees
{
myservo_tilt.write(pos);
delay(15);
}
}

One Response to “Test program Sweep and Tilt”

  1. admin says:

    This is a laborious program and is calling out for functions to be defined! Clearly the next task.
    David

Leave a Reply

You must be logged in to post a comment.