user11551: Ok so I've used nicks code and have the code running once ok.... I the noticed however I had a fast 180 sweep and then it returned under control of code. I then noticed the comments wrt pulselen of 1000 being zero degrees and using 1500 as 90 degrees.... Wow so I get a single movement which holds but it doesn't go 90 degrees...
I'm using an Adafruit servo shield.
I can make my servo move. However, I want to stop it at 90 degrees without it returning to 0 degrees each time.
What am I missing?
The code I've used is as follows:
void setup()
{
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
}

void loop()
{
  for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++)
  {
    pwm.setPWM(0, 0, pulselen);
  }
  delay(500);
}


user10794: The code in loop is called repeatedly. Thus it does this:

Go from SERVOMIN to SERVOMAX very rapidly (I measured 72 ms)
Pause half a second
Repeat the above

To make it pause at SERVOMAX you need to either not repeat the loop, or put it all in setup, eg.
#include <Adafruit_PWMServoDriver.h>
#include <Wire.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)
void setup()
{
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++)
  {
    pwm.setPWM(0, 0, pulselen);
  }

}

void loop()
{
}


11551: <p>Ok so I've used nicks code and have the code running once ok.... I the noticed however I had a fast 180 sweep and then it returned under control of code. I then noticed the comments wrt pulselen of 1000 being zero degrees and using 1500 as 90 degrees.... Wow so I get a single movement which holds but it doesn't go 90 degrees...</p>

<p>I'm using an Adafruit servo shield.</p>

<p>I can make my servo move. However, I want to stop it at 90 degrees <em>without</em> it returning to 0 degrees each time.</p>

<p>What am I missing?</p>

<p>The code I've used is as follows:</p>

<pre class="lang-c prettyprint-override"><code>void setup()
{
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
}

void loop()
{
  for (uint16_t pulselen = SERVOMIN; pulselen &lt; SERVOMAX; pulselen++)
  {
    pwm.setPWM(0, 0, pulselen);
  }
  delay(500);
}
</code></pre>
 10794: 

<p>The code in <code>loop</code> is called repeatedly. Thus it does this:</p>

<ul>
<li>Go from SERVOMIN to SERVOMAX very rapidly (I measured 72 ms)</li>
<li>Pause half a second</li>
<li>Repeat the above</li>
</ul>

<p>To make it pause at SERVOMAX you need to either not repeat the loop, or put it all in <code>setup</code>, eg.</p>

<pre class="lang-C++ prettyprint-override"><code>#include &lt;Adafruit_PWMServoDriver.h&gt;
#include &lt;Wire.h&gt;

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)
void setup()
{
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  for (uint16_t pulselen = SERVOMIN; pulselen &lt; SERVOMAX; pulselen++)
  {
    pwm.setPWM(0, 0, pulselen);
  }

}

void loop()
{
}
</code></pre>
