Better Servo Sweep example

I have changed the sweep example for educational reasons. We use this in our courses (high school and college) so please adjust under https://www.arduino.cc/en/Tutorial/Sweep as well, it is a bad habit to have fixed values everywhere in the code especially if one uses it in education.

// Sweep
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.
// Addition by J.A. Korten Aug 29, 2015

#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 
const int servoMin = 0; // set to your observed min value
const int servoMax = 180; // set to your observed max value
const int servoPin = 9; // PWM pin where the servo is attached to
const int servoDelay = 15; // delay in the loop, smaller: higher speed (maybe too high), larger: slower servo. 

 
void setup() 
{ 
  myservo.attach(servoPin);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  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(servoDelay);                       // waits 15ms for the servo to reach the position 
  } 
  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(servoDelay);                       // waits 15ms for the servo to reach the position 
  } 
}

jopiek:
so please adjust under https://www.arduino.cc/en/Tutorial/Sweep as well

Yours are probably good changes but don’t hold your breath.

…R