Slightly modified to support AFMotor by passing in function pointers

This commit is contained in:
Ladyada 2011-01-04 13:34:01 -05:00
commit 843e9aa771
25 changed files with 4171 additions and 0 deletions

351
AccelStepper.cpp Normal file
View file

@ -0,0 +1,351 @@
// AccelStepper.cpp
//
// Copyright (C) 2009 Mike McCauley
// $Id: AccelStepper.cpp,v 1.2 2010/10/24 07:46:18 mikem Exp mikem $
#include "WProgram.h"
#include "AccelStepper.h"
void AccelStepper::moveTo(long absolute)
{
_targetPos = absolute;
computeNewSpeed();
}
void AccelStepper::move(long relative)
{
moveTo(_currentPos + relative);
}
// Implements steps according to the current speed
// You must call this at least once per step
// returns true if a step occurred
boolean AccelStepper::runSpeed()
{
unsigned long time = millis();
if (time > _lastStepTime + _stepInterval)
{
if (_speed > 0)
{
// Clockwise
_currentPos += 1;
}
else if (_speed < 0)
{
// Anticlockwise
_currentPos -= 1;
}
step(_currentPos & 0x3); // Bottom 2 bits (same as mod 4, but works with + and - numbers)
_lastStepTime = time;
return true;
}
else
return false;
}
long AccelStepper::distanceToGo()
{
return _targetPos - _currentPos;
}
long AccelStepper::targetPosition()
{
return _targetPos;
}
long AccelStepper::currentPosition()
{
return _currentPos;
}
// Useful during initialisations or after initial positioning
void AccelStepper::setCurrentPosition(long position)
{
_currentPos = position;
}
void AccelStepper::computeNewSpeed()
{
setSpeed(desiredSpeed());
}
// Work out and return a new speed.
// Subclasses can override if they want
// Implement acceleration, deceleration and max speed
// Negative speed is anticlockwise
// This is called:
// after each step
// after user changes:
// maxSpeed
// acceleration
// target position (relative or absolute)
float AccelStepper::desiredSpeed()
{
long distanceTo = distanceToGo();
// Max possible speed that can still decelerate in the available distance
float requiredSpeed;
if (distanceTo == 0)
return 0.0; // Were there
else if (distanceTo > 0) // Clockwise
requiredSpeed = sqrt(2.0 * distanceTo * _acceleration);
else // Anticlockwise
requiredSpeed = -sqrt(2.0 * -distanceTo * _acceleration);
if (requiredSpeed > _speed)
{
// Need to accelerate in clockwise direction
if (_speed == 0)
requiredSpeed = sqrt(2.0 * _acceleration);
else
requiredSpeed = _speed + abs(_acceleration / _speed);
if (requiredSpeed > _maxSpeed)
requiredSpeed = _maxSpeed;
}
else if (requiredSpeed < _speed)
{
// Need to accelerate in anticlockwise direction
if (_speed == 0)
requiredSpeed = -sqrt(2.0 * _acceleration);
else
requiredSpeed = _speed - abs(_acceleration / _speed);
if (requiredSpeed < -_maxSpeed)
requiredSpeed = -_maxSpeed;
}
// Serial.println(requiredSpeed);
return requiredSpeed;
}
// Run the motor to implement speed and acceleration in order to proceed to the target position
// You must call this at least once per step, preferably in your main loop
// If the motor is in the desired position, the cost is very small
// returns true if we are still running to position
boolean AccelStepper::run()
{
if (_targetPos == _currentPos)
return false;
if (runSpeed())
computeNewSpeed();
return true;
}
AccelStepper::AccelStepper(uint8_t pins, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4)
{
_pins = pins;
_currentPos = 0;
_targetPos = 0;
_speed = 0.0;
_maxSpeed = 1.0;
_acceleration = 1.0;
_stepInterval = 0;
_lastStepTime = 0;
_pin1 = pin1;
_pin2 = pin2;
_pin3 = pin3;
_pin4 = pin4;
enableOutputs();
}
AccelStepper::AccelStepper(void (*forward)(), void (*backward)())
{
_pins = 0;
_currentPos = 0;
_targetPos = 0;
_speed = 0.0;
_maxSpeed = 1.0;
_acceleration = 1.0;
_stepInterval = 0;
_lastStepTime = 0;
_pin1 = 0;
_pin2 = 0;
_pin3 = 0;
_pin4 = 0;
_forward = forward;
_backward = backward;
}
void AccelStepper::setMaxSpeed(float speed)
{
_maxSpeed = speed;
computeNewSpeed();
}
void AccelStepper::setAcceleration(float acceleration)
{
_acceleration = acceleration;
computeNewSpeed();
}
void AccelStepper::setSpeed(float speed)
{
_speed = speed;
_stepInterval = abs(1000.0 / _speed);
}
float AccelStepper::speed()
{
return _speed;
}
// Subclasses can override
void AccelStepper::step(uint8_t step)
{
switch (_pins)
{
case 0:
step0();
break;
case 1:
step1(step);
break;
case 2:
step2(step);
break;
case 4:
step4(step);
break;
}
}
// 0 pin step function (ie for functional usage)
void AccelStepper::step0()
{
if (_speed) {
_forward();
} else {
_backward();
}
}
// 1 pin step function (ie for stepper drivers)
// This is passed the current step number (0 to 3)
// Subclasses can override
void AccelStepper::step1(uint8_t step)
{
digitalWrite(_pin2, _speed > 0); // Direction
// Caution 200ns setup time
digitalWrite(_pin1, HIGH);
// Caution, min Step pulse width for 3967 is 1microsec
// Delay 1microsec
delayMicroseconds(1);
digitalWrite(_pin1, LOW);
}
// 2 pin step function
// This is passed the current step number (0 to 3)
// Subclasses can override
void AccelStepper::step2(uint8_t step)
{
switch (step)
{
case 0: /* 01 */
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, HIGH);
break;
case 1: /* 11 */
digitalWrite(_pin1, HIGH);
digitalWrite(_pin2, HIGH);
break;
case 2: /* 10 */
digitalWrite(_pin1, HIGH);
digitalWrite(_pin2, LOW);
break;
case 3: /* 00 */
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
break;
}
}
// 4 pin step function
// This is passed the current step number (0 to 3)
// Subclasses can override
void AccelStepper::step4(uint8_t step)
{
switch (step)
{
case 0: // 1010
digitalWrite(_pin1, HIGH);
digitalWrite(_pin2, LOW);
digitalWrite(_pin3, HIGH);
digitalWrite(_pin4, LOW);
break;
case 1: // 0110
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, HIGH);
digitalWrite(_pin3, HIGH);
digitalWrite(_pin4, LOW);
break;
case 2: //0101
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, HIGH);
digitalWrite(_pin3, LOW);
digitalWrite(_pin4, HIGH);
break;
case 3: //1001
digitalWrite(_pin1, HIGH);
digitalWrite(_pin2, LOW);
digitalWrite(_pin3, LOW);
digitalWrite(_pin4, HIGH);
break;
}
}
// Prevents power consumption on the outputs
void AccelStepper::disableOutputs()
{
if (! _pins) return;
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
if (_pins == 4)
{
digitalWrite(_pin3, LOW);
digitalWrite(_pin4, LOW);
}
}
void AccelStepper::enableOutputs()
{
if (! _pins) return;
pinMode(_pin1, OUTPUT);
pinMode(_pin2, OUTPUT);
if (_pins == 4)
{
pinMode(_pin3, OUTPUT);
pinMode(_pin4, OUTPUT);
}
}
// Blocks until the target position is reached
void AccelStepper::runToPosition()
{
while (run())
;
}
boolean AccelStepper::runSpeedToPosition()
{
return _targetPos!=_currentPos ? AccelStepper::runSpeed() : false;
}
// Blocks until the new target position is reached
void AccelStepper::runToNewPosition(long position)
{
moveTo(position);
runToPosition();
}

333
AccelStepper.h Normal file
View file

@ -0,0 +1,333 @@
// AccelStepper.h
//
/// \mainpage AccelStepper library for Arduino
///
/// This is the Arduino AccelStepper 1.2 library.
/// It provides an object-oriented interface for 2 or 4 pin stepper motors.
///
/// The standard Arduino IDE includes the Stepper library
/// (http://arduino.cc/en/Reference/Stepper) for stepper motors. It is
/// perfectly adequate for simple, single motor applications.
///
/// AccelStepper significantly improves on the standard Arduino Stepper library in several ways:
/// \li Supports acceleration and deceleration
/// \li Supports multiple simultaneous steppers, with independent concurrent stepping on each stepper
/// \li API functions never delay() or block
/// \li Supports 2 and 4 wire steppers
/// \li Supports stepper drivers such as the Sparkfun EasyDriver (based on 3967 driver chip)
/// \li Very slow speeds are supported
/// \li Extensive API
/// \li Subclass support
///
/// The latest version of this documentation can be downloaded from
/// http://www.open.com.au/mikem/arduino/AccelStepper
///
/// Example Arduino programs are included to show the main modes of use.
///
/// The version of the package that this documentation refers to can be downloaded
/// from http://www.open.com.au/mikem/arduino/AccelStepper/AccelStepper-1.3.zip
/// You can find the latest version at http://www.open.com.au/mikem/arduino/AccelStepper
///
/// Tested on Arduino Diecimila and Mega with arduino-0018 on OpenSuSE 11.1 and avr-libc-1.6.1-1.15,
/// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5.
///
/// \par Installation
/// Install in the usual way: unzip the distribution zip file to the libraries
/// sub-folder of your sketchbook.
///
/// This software is Copyright (C) 2010 Mike McCauley. Use is subject to license
/// conditions. The main licensing options available are GPL V2 or Commercial:
///
/// \par Open Source Licensing GPL V2
/// This is the appropriate option if you want to share the source code of your
/// application with everyone you distribute it to, and you also want to give them
/// the right to share who uses it. If you wish to use this software under Open
/// Source Licensing, you must contribute all your source code to the open source
/// community in accordance with the GPL Version 2 when your application is
/// distributed. See http://www.gnu.org/copyleft/gpl.html
///
/// \par Commercial Licensing
/// This is the appropriate option if you are creating proprietary applications
/// and you are not prepared to distribute and share the source code of your
/// application. Contact info@open.com.au for details.
///
/// \par Revision History
/// \version 1.0 Initial release
///
/// \version 1.1 Added speed() function to get the current speed.
/// \version 1.2 Added runSpeedToPosition() submitted by Gunnar Arndt.
/// \version 1.3 Added support for stepper drivers (ie with Step and Direction inputs) with _pins == 1
///
///
/// \author Mike McCauley (mikem@open.com.au)
// Copyright (C) 2009 Mike McCauley
// $Id: AccelStepper.h,v 1.2 2010/10/24 07:46:18 mikem Exp mikem $
#ifndef AccelStepper_h
#define AccelStepper_h
#include <stdlib.h>
#include <wiring.h>
// These defs cause trouble on some versions of Arduino
#undef round
/////////////////////////////////////////////////////////////////////
/// \class AccelStepper AccelStepper.h <AccelStepper.h>
/// \brief Support for stepper motors with acceleration etc.
///
/// This defines a single 2 or 4 pin stepper motor, or stepper moter with fdriver chip, with optional
/// acceleration, deceleration, absolute positioning commands etc. Multiple
/// simultaneous steppers are supported, all moving
/// at different speeds and accelerations.
///
/// \par Operation
/// This module operates by computing a step time in milliseconds. The step
/// time is recomputed after each step and after speed and acceleration
/// parameters are changed by the caller. The time of each step is recorded in
/// milliseconds. The run() function steps the motor if a new step is due.
/// The run() function must be called frequently until the motor is in the
/// desired position, after which time run() will do nothing.
///
/// \par Positioning
/// Positions are specified by a signed long integer. At
/// construction time, the current position of the motor is consider to be 0. Positive
/// positions are clockwise from the initial position; negative positions are
/// anticlockwise. The curent position can be altered for instance after
/// initialization positioning.
///
/// \par Caveats
/// This is an open loop controller: If the motor stalls or is oversped,
/// AccelStepper will not have a correct
/// idea of where the motor really is (since there is no feedback of the motor's
/// real position. We only know where we _think_ it is, relative to the
/// initial starting point).
///
/// The fastest motor speed that can be reliably supported is 1000 steps per
/// second (1 step every millisecond). However any speed less than that down
/// to very slow speeds (much less than one per second) are supported,
/// provided the run() function is called frequently enough to step the
/// motor whenever required.
class AccelStepper
{
public:
/// Constructor. You can have multiple simultaneous steppers, all moving
/// at different speeds and accelerations, provided you call their run()
/// functions at frequent enough intervals. Current Position is set to 0, target
/// position is set to 0. MaxSpeed and Acceleration default to 1.0.
/// The motor pins will be initialised to OUTPUT mode during the
/// constructor by a call to enableOutputs().
/// \param[in] pins Number of pins to interface to. 1, 2 or 4 are
/// supported. 1 means a stepper driver (with Step and Direction pins)
/// 2 means a 2 wire stepper. 4 means a 4 wire stepper.
/// Defaults to 4 pins.
/// \param[in] pin1 Arduino digital pin number for motor pin 1. Defaults
/// to pin 2. For a driver (pins==1), this is the Step input to the driver. Low to high transition means to step)
/// \param[in] pin2 Arduino digital pin number for motor pin 2. Defaults
/// to pin 3. For a driver (pins==1), this is the Direction input the driver. High means forward.
/// \param[in] pin3 Arduino digital pin number for motor pin 3. Defaults
/// to pin 4.
/// \param[in] pin4 Arduino digital pin number for motor pin 4. Defaults
/// to pin 5.
AccelStepper(uint8_t pins = 4, uint8_t pin1 = 2, uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5);
/// Constructor. You can have multiple simultaneous steppers, all moving
/// at different speeds and accelerations, provided you call their run()
/// functions at frequent enough intervals. Current Position is set to 0, target
/// position is set to 0. MaxSpeed and Acceleration default to 1.0.
/// Any motor initialization should happen before hand, no pins are used or initialized.
/// \param[in] forward void-returning procedure that will make a forward step
/// \param[in] backward void-returning procedure that will make a backward step
AccelStepper(void (*forward)(), void (*backward)());
/// Set the target position. The run() function will try to move the motor
/// from the current position to the target position set by the most
/// recent call to this function.
/// \param[in] absolute The desired absolute position. Negative is
/// anticlockwise from the 0 position.
void moveTo(long absolute);
/// Set the target position relative to the current position
/// \param[in] relative The desired position relative to the current position. Negative is
/// anticlockwise from the current position.
void move(long relative);
/// Poll the motor and step it if a step is due, implementing
/// accelerations and decelerations to achive the ratget position. You must call this as
/// fequently as possible, but at least once per minimum step interval,
/// preferably in your main loop.
/// \return true if the motor is at the target position.
boolean run();
/// Poll the motor and step it if a step is due, implmenting a constant
/// speed as set by the most recent call to setSpeed().
/// \return true if the motor was stepped.
boolean runSpeed();
/// Sets the maximum permitted speed. the run() function will accelerate
/// up to the speed set by this function.
/// \param[in] speed The desired maximum speed in steps per second. Must
/// be > 0. Speeds of more than 1000 steps per second are unreliable.
void setMaxSpeed(float speed);
/// Sets the acceleration and deceleration parameter.
/// \param[in] acceleration The desired acceleration in steps per second
/// per second. Must be > 0.
void setAcceleration(float acceleration);
/// Sets the desired constant speed for use with runSpeed().
/// \param[in] speed The desired constant speed in steps per
/// second. Positive is clockwise. Speeds of more than 1000 steps per
/// second are unreliable. Very slow speeds may be set (eg 0.00027777 for
/// once per hour, approximately. Speed accuracy depends on the Arduino
/// crystal. Jitter depends on how frequently you call the runSpeed() function.
void setSpeed(float speed);
/// The most recently set speed
/// \return the most recent speed in steps per second
float speed();
/// The distance from the current position to the target position.
/// \return the distance from the current position to the target position
/// in steps. Positive is clockwise from the current position.
long distanceToGo();
/// The most recently set target position.
/// \return the target position
/// in steps. Positive is clockwise from the 0 position.
long targetPosition();
/// The currently motor position.
/// \return the current motor position
/// in steps. Positive is clockwise from the 0 position.
long currentPosition();
/// Resets the current position of the motor, so that wherever the mottor
/// happens to be right now is considered to be the new position. Useful
/// for setting a zero position on a stepper after an initial hardware
/// positioning move.
/// \param[in] position The position in steps of wherever the motor
/// happens to be right now.
void setCurrentPosition(long position);
/// Moves the motor to the target position and blocks until it is at
/// position. Dont use this in event loops, since it blocks.
void runToPosition();
/// Runs at the currently selected speed until the target position is reached
/// Does not implement accelerations.
boolean runSpeedToPosition();
/// Moves the motor to the new target position and blocks until it is at
/// position. Dont use this in event loops, since it blocks.
/// \param[in] position The new target position.
void runToNewPosition(long position);
/// Disable motor pin outputs by setting them all LOW
/// Depending on the design of your electronics this may turn off
/// the power to the motor coils, saving power.
/// This is useful to support Arduino low power modes: disable the outputs
/// during sleep and then reenable with enableOutputs() before stepping
/// again.
void disableOutputs();
/// Enable motor pin outputs by setting the motor pins to OUTPUT
/// mode. Called automatically by the constructor.
void enableOutputs();
protected:
/// Forces the library to compute a new instantaneous speed and set that as
/// the current speed. Calls
/// desiredSpeed(), which can be overridden by subclasses. It is called by
/// the library:
/// \li after each step
/// \li after change to maxSpeed through setMaxSpeed()
/// \li after change to acceleration through setAcceleration()
/// \li after change to target position (relative or absolute) through
/// move() or moveTo()
void computeNewSpeed();
/// Called to execute a step. Only called when a new step is
/// required. Subclasses may override to implement new stepping
/// interfaces. The default calls step1(), step2() or step4() depending on the
/// number of pins defined for the stepper.
/// \param[in] step The current step phase number (0 to 3)
virtual void step(uint8_t step);
/// Called to execute a step using stepper functions (pins = 0) Only called when a new step is
/// required. Calls _forward() or _backward() to perform the step
virtual void step0(void);
/// Called to execute a step on a stepper drover (ie where pins == 1). Only called when a new step is
/// required. Subclasses may override to implement new stepping
/// interfaces. The default sets or clears the outputs of Step pin1 to step,
/// and sets the output of _pin2 to the desired direction. The Step pin (_pin1) is pulsed for 1 microsecond
/// which is the minimum STEP pulse width for the 3967 driver.
/// \param[in] step The current step phase number (0 to 3)
virtual void step1(uint8_t step);
/// Called to execute a step on a 2 pin motor. Only called when a new step is
/// required. Subclasses may override to implement new stepping
/// interfaces. The default sets or clears the outputs of pin1 and pin2
/// \param[in] step The current step phase number (0 to 3)
virtual void step2(uint8_t step);
/// Called to execute a step on a 4 pin motor. Only called when a new step is
/// required. Subclasses may override to implement new stepping
/// interfaces. The default sets or clears the outputs of pin1, pin2,
/// pin3, pin4.
/// \param[in] step The current step phase number (0 to 3)
virtual void step4(uint8_t step);
/// Compute and return the desired speed. The default algorithm uses
/// maxSpeed, acceleration and the current speed to set a new speed to
/// move the motor from teh current position to the target
/// position. Subclasses may override this to provide an alternate
/// algorithm (but do not block). Called by computeNewSpeed whenever a new speed neds to be
/// computed.
virtual float desiredSpeed();
private:
/// Number of pins on the stepper motor. Permits 2 or 4. 2 pins is a
/// bipolar, and 4 pins is a unipolar.
uint8_t _pins; // 2 or 4
/// Arduino pin number for the 2 or 4 pins required to interface to the
/// stepper motor.
uint8_t _pin1, _pin2, _pin3, _pin4;
/// The current absolution position in steps.
long _currentPos; // Steps
/// The target position in steps. The AccelStepper library will move the
/// motor from teh _currentPos to the _targetPos, taking into account the
/// max speed, acceleration and deceleration
long _targetPos; // Steps
/// The current motos speed in steps per second
/// Positive is clockwise
float _speed; // Steps per second
/// The maximum permitted speed in steps per second. Must be > 0.
float _maxSpeed;
/// The acceleration to use to accelerate or decelerate the motor in steps
/// per second per second. Must be > 0
float _acceleration;
/// The current interval between steps in milliseconds.
unsigned long _stepInterval;
/// The last step time in milliseconds
unsigned long _lastStepTime;
// The pointer to a forward-step procedure
void (*_forward)();
// The pointer to a backward-step procedure
void (*_backward)();
};
#endif

17
LICENSE Normal file
View file

@ -0,0 +1,17 @@
This software is Copyright (C) 2008 Mike McCauley. Use is subject to license
conditions. The main licensing options available are GPL V2 or Commercial:
Open Source Licensing GPL V2
This is the appropriate option if you want to share the source code of your
application with everyone you distribute it to, and you also want to give them
the right to share who uses it. If you wish to use this software under Open
Source Licensing, you must contribute all your source code to the open source
community in accordance with the GPL Version 2 when your application is
distributed. See http://www.gnu.org/copyleft/gpl.html
Commercial Licensing
This is the appropriate option if you are creating proprietary applications
and you are not prepared to distribute and share the source code of your
application. Contact info@open.com.au for details.

27
MANIFEST Normal file
View file

@ -0,0 +1,27 @@
AccelStepper/Makefile
AccelStepper/AccelStepper.h
AccelStepper/AccelStepper.cpp
AccelStepper/MANIFEST
AccelStepper/LICENSE
AccelStepper/project.cfg
AccelStepper/doc
AccelStepper/examples/Blocking/Blocking.pde
AccelStepper/examples/MultiStepper/MultiStepper.pde
AccelStepper/examples/Overshoot/Overshoot.pde
AccelStepper/examples/ConstantSpeed/ConstantSpeed.pde
AccelStepper/examples/Random/Random.pde
AccelStepper/doc
AccelStepper/doc/index.html
AccelStepper/doc/functions.html
AccelStepper/doc/annotated.html
AccelStepper/doc/tab_l.gif
AccelStepper/doc/tabs.css
AccelStepper/doc/files.html
AccelStepper/doc/classAccelStepper-members.html
AccelStepper/doc/doxygen.css
AccelStepper/doc/AccelStepper_8h-source.html
AccelStepper/doc/tab_r.gif
AccelStepper/doc/doxygen.png
AccelStepper/doc/tab_b.gif
AccelStepper/doc/functions_func.html
AccelStepper/doc/classAccelStepper.html

26
Makefile Normal file
View file

@ -0,0 +1,26 @@
# Makefile
#
# Makefile for the Arduino AccelStepper project
#
# Author: Mike McCauley (mikem@open.com.au)
# Copyright (C) 2010 Mike McCauley
# $Id: Makefile,v 1.1 2010/04/25 02:21:18 mikem Exp mikem $
PROJNAME = AccelStepper
# Dont forget to also change the version at the top of AccelStepper.h:
DISTFILE = $(PROJNAME)-1.3.zip
all: doxygen dist upload
doxygen:
doxygen project.cfg
ci:
ci -l `cat MANIFEST`
dist:
(cd ..; zip $(PROJNAME)/$(DISTFILE) `cat $(PROJNAME)/MANIFEST`)
upload:
scp $(DISTFILE) doc/*.html doc/*.gif doc/*.png doc/*.css doc/*.pdf server2:/var/www/html/mikem/arduino/$(PROJNAME)

View file

@ -0,0 +1,336 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: AccelStepper.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>AccelStepper.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// AccelStepper.h</span>
<a name="l00002"></a>00002 <span class="comment">//</span><span class="comment"></span>
<a name="l00003"></a>00003 <span class="comment">/// \mainpage AccelStepper library for Arduino</span>
<a name="l00004"></a>00004 <span class="comment">///</span>
<a name="l00005"></a>00005 <span class="comment">/// This is the Arduino AccelStepper 1.2 library.</span>
<a name="l00006"></a>00006 <span class="comment">/// It provides an object-oriented interface for 2 or 4 pin stepper motors.</span>
<a name="l00007"></a>00007 <span class="comment">///</span>
<a name="l00008"></a>00008 <span class="comment">/// The standard Arduino IDE includes the Stepper library</span>
<a name="l00009"></a>00009 <span class="comment">/// (http://arduino.cc/en/Reference/Stepper) for stepper motors. It is</span>
<a name="l00010"></a>00010 <span class="comment">/// perfectly adequate for simple, single motor applications.</span>
<a name="l00011"></a>00011 <span class="comment">///</span>
<a name="l00012"></a>00012 <span class="comment">/// AccelStepper significantly improves on the standard Arduino Stepper library in several ways:</span>
<a name="l00013"></a>00013 <span class="comment">/// \li Supports acceleration and deceleration</span>
<a name="l00014"></a>00014 <span class="comment">/// \li Supports multiple simultaneous steppers, with independent concurrent stepping on each stepper</span>
<a name="l00015"></a>00015 <span class="comment">/// \li API functions never delay() or block</span>
<a name="l00016"></a>00016 <span class="comment">/// \li Supports 2 and 4 wire steppers</span>
<a name="l00017"></a>00017 <span class="comment">/// \li Supports stepper drivers such as the Sparkfun EasyDriver (based on 3967 driver chip)</span>
<a name="l00018"></a>00018 <span class="comment">/// \li Very slow speeds are supported</span>
<a name="l00019"></a>00019 <span class="comment">/// \li Extensive API</span>
<a name="l00020"></a>00020 <span class="comment">/// \li Subclass support</span>
<a name="l00021"></a>00021 <span class="comment">///</span>
<a name="l00022"></a>00022 <span class="comment">/// The latest version of this documentation can be downloaded from </span>
<a name="l00023"></a>00023 <span class="comment">/// http://www.open.com.au/mikem/arduino/AccelStepper</span>
<a name="l00024"></a>00024 <span class="comment">///</span>
<a name="l00025"></a>00025 <span class="comment">/// Example Arduino programs are included to show the main modes of use.</span>
<a name="l00026"></a>00026 <span class="comment">///</span>
<a name="l00027"></a>00027 <span class="comment">/// The version of the package that this documentation refers to can be downloaded </span>
<a name="l00028"></a>00028 <span class="comment">/// from http://www.open.com.au/mikem/arduino/AccelStepper/AccelStepper-1.3.zip</span>
<a name="l00029"></a>00029 <span class="comment">/// You can find the latest version at http://www.open.com.au/mikem/arduino/AccelStepper</span>
<a name="l00030"></a>00030 <span class="comment">///</span>
<a name="l00031"></a>00031 <span class="comment">/// Tested on Arduino Diecimila and Mega with arduino-0018 on OpenSuSE 11.1 and avr-libc-1.6.1-1.15,</span>
<a name="l00032"></a>00032 <span class="comment">/// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5.</span>
<a name="l00033"></a>00033 <span class="comment">///</span>
<a name="l00034"></a>00034 <span class="comment">/// \par Installation</span>
<a name="l00035"></a>00035 <span class="comment">/// Install in the usual way: unzip the distribution zip file to the libraries</span>
<a name="l00036"></a>00036 <span class="comment">/// sub-folder of your sketchbook. </span>
<a name="l00037"></a>00037 <span class="comment">///</span>
<a name="l00038"></a>00038 <span class="comment">/// This software is Copyright (C) 2010 Mike McCauley. Use is subject to license</span>
<a name="l00039"></a>00039 <span class="comment">/// conditions. The main licensing options available are GPL V2 or Commercial:</span>
<a name="l00040"></a>00040 <span class="comment">/// </span>
<a name="l00041"></a>00041 <span class="comment">/// \par Open Source Licensing GPL V2</span>
<a name="l00042"></a>00042 <span class="comment">/// This is the appropriate option if you want to share the source code of your</span>
<a name="l00043"></a>00043 <span class="comment">/// application with everyone you distribute it to, and you also want to give them</span>
<a name="l00044"></a>00044 <span class="comment">/// the right to share who uses it. If you wish to use this software under Open</span>
<a name="l00045"></a>00045 <span class="comment">/// Source Licensing, you must contribute all your source code to the open source</span>
<a name="l00046"></a>00046 <span class="comment">/// community in accordance with the GPL Version 2 when your application is</span>
<a name="l00047"></a>00047 <span class="comment">/// distributed. See http://www.gnu.org/copyleft/gpl.html</span>
<a name="l00048"></a>00048 <span class="comment">/// </span>
<a name="l00049"></a>00049 <span class="comment">/// \par Commercial Licensing</span>
<a name="l00050"></a>00050 <span class="comment">/// This is the appropriate option if you are creating proprietary applications</span>
<a name="l00051"></a>00051 <span class="comment">/// and you are not prepared to distribute and share the source code of your</span>
<a name="l00052"></a>00052 <span class="comment">/// application. Contact info@open.com.au for details.</span>
<a name="l00053"></a>00053 <span class="comment">///</span>
<a name="l00054"></a>00054 <span class="comment">/// \par Revision History</span>
<a name="l00055"></a>00055 <span class="comment">/// \version 1.0 Initial release</span>
<a name="l00056"></a>00056 <span class="comment">///</span>
<a name="l00057"></a>00057 <span class="comment">/// \version 1.1 Added speed() function to get the current speed.</span>
<a name="l00058"></a>00058 <span class="comment">/// \version 1.2 Added runSpeedToPosition() submitted by Gunnar Arndt.</span>
<a name="l00059"></a>00059 <span class="comment">/// \version 1.3 Added support for stepper drivers (ie with Step and Direction inputs) with _pins == 1</span>
<a name="l00060"></a>00060 <span class="comment">/// </span>
<a name="l00061"></a>00061 <span class="comment">///</span>
<a name="l00062"></a>00062 <span class="comment">/// \author Mike McCauley (mikem@open.com.au)</span>
<a name="l00063"></a>00063 <span class="comment"></span><span class="comment">// Copyright (C) 2009 Mike McCauley</span>
<a name="l00064"></a>00064 <span class="comment">// $Id: AccelStepper.h,v 1.2 2010/10/24 07:46:18 mikem Exp mikem $</span>
<a name="l00065"></a>00065
<a name="l00066"></a>00066 <span class="preprocessor">#ifndef AccelStepper_h</span>
<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#define AccelStepper_h</span>
<a name="l00068"></a>00068 <span class="preprocessor"></span>
<a name="l00069"></a>00069 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00070"></a>00070 <span class="preprocessor">#include &lt;wiring.h&gt;</span>
<a name="l00071"></a>00071
<a name="l00072"></a>00072 <span class="comment">// These defs cause trouble on some versions of Arduino</span>
<a name="l00073"></a>00073 <span class="preprocessor">#undef round</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00075"></a>00075 <span class="comment">/////////////////////////////////////////////////////////////////////</span>
<a name="l00076"></a>00076 <span class="comment">/// \class AccelStepper AccelStepper.h &lt;AccelStepper.h&gt;</span>
<a name="l00077"></a>00077 <span class="comment">/// \brief Support for stepper motors with acceleration etc.</span>
<a name="l00078"></a>00078 <span class="comment">///</span>
<a name="l00079"></a>00079 <span class="comment">/// This defines a single 2 or 4 pin stepper motor, or stepper moter with fdriver chip, with optional</span>
<a name="l00080"></a>00080 <span class="comment">/// acceleration, deceleration, absolute positioning commands etc. Multiple</span>
<a name="l00081"></a>00081 <span class="comment">/// simultaneous steppers are supported, all moving </span>
<a name="l00082"></a>00082 <span class="comment">/// at different speeds and accelerations. </span>
<a name="l00083"></a>00083 <span class="comment">///</span>
<a name="l00084"></a>00084 <span class="comment">/// \par Operation</span>
<a name="l00085"></a>00085 <span class="comment">/// This module operates by computing a step time in milliseconds. The step</span>
<a name="l00086"></a>00086 <span class="comment">/// time is recomputed after each step and after speed and acceleration</span>
<a name="l00087"></a>00087 <span class="comment">/// parameters are changed by the caller. The time of each step is recorded in</span>
<a name="l00088"></a>00088 <span class="comment">/// milliseconds. The run() function steps the motor if a new step is due.</span>
<a name="l00089"></a>00089 <span class="comment">/// The run() function must be called frequently until the motor is in the</span>
<a name="l00090"></a>00090 <span class="comment">/// desired position, after which time run() will do nothing.</span>
<a name="l00091"></a>00091 <span class="comment">///</span>
<a name="l00092"></a>00092 <span class="comment">/// \par Positioning</span>
<a name="l00093"></a>00093 <span class="comment">/// Positions are specified by a signed long integer. At</span>
<a name="l00094"></a>00094 <span class="comment">/// construction time, the current position of the motor is consider to be 0. Positive</span>
<a name="l00095"></a>00095 <span class="comment">/// positions are clockwise from the initial position; negative positions are</span>
<a name="l00096"></a>00096 <span class="comment">/// anticlockwise. The curent position can be altered for instance after</span>
<a name="l00097"></a>00097 <span class="comment">/// initialization positioning.</span>
<a name="l00098"></a>00098 <span class="comment">///</span>
<a name="l00099"></a>00099 <span class="comment">/// \par Caveats</span>
<a name="l00100"></a>00100 <span class="comment">/// This is an open loop controller: If the motor stalls or is oversped,</span>
<a name="l00101"></a>00101 <span class="comment">/// AccelStepper will not have a correct </span>
<a name="l00102"></a>00102 <span class="comment">/// idea of where the motor really is (since there is no feedback of the motor's</span>
<a name="l00103"></a>00103 <span class="comment">/// real position. We only know where we _think_ it is, relative to the</span>
<a name="l00104"></a>00104 <span class="comment">/// initial starting point).</span>
<a name="l00105"></a>00105 <span class="comment">///</span>
<a name="l00106"></a>00106 <span class="comment">/// The fastest motor speed that can be reliably supported is 1000 steps per</span>
<a name="l00107"></a>00107 <span class="comment">/// second (1 step every millisecond). However any speed less than that down</span>
<a name="l00108"></a>00108 <span class="comment">/// to very slow speeds (much less than one per second) are supported,</span>
<a name="l00109"></a>00109 <span class="comment">/// provided the run() function is called frequently enough to step the</span>
<a name="l00110"></a>00110 <span class="comment">/// motor whenever required.</span>
<a name="l00111"></a><a class="code" href="classAccelStepper.html">00111</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="classAccelStepper.html" title="Support for stepper motors with acceleration etc.">AccelStepper</a>
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113 <span class="keyword">public</span>:<span class="comment"></span>
<a name="l00114"></a>00114 <span class="comment"> /// Constructor. You can have multiple simultaneous steppers, all moving</span>
<a name="l00115"></a>00115 <span class="comment"> /// at different speeds and accelerations, provided you call their run()</span>
<a name="l00116"></a>00116 <span class="comment"> /// functions at frequent enough intervals. Current Position is set to 0, target</span>
<a name="l00117"></a>00117 <span class="comment"> /// position is set to 0. MaxSpeed and Acceleration default to 1.0.</span>
<a name="l00118"></a>00118 <span class="comment"> /// The motor pins will be initialised to OUTPUT mode during the</span>
<a name="l00119"></a>00119 <span class="comment"> /// constructor by a call to enableOutputs().</span>
<a name="l00120"></a>00120 <span class="comment"> /// \param[in] pins Number of pins to interface to. 1, 2 or 4 are</span>
<a name="l00121"></a>00121 <span class="comment"> /// supported. 1 means a stepper driver (with Step and Direction pins)</span>
<a name="l00122"></a>00122 <span class="comment"> /// 2 means a 2 wire stepper. 4 means a 4 wire stepper.</span>
<a name="l00123"></a>00123 <span class="comment"> /// Defaults to 4 pins.</span>
<a name="l00124"></a>00124 <span class="comment"> /// \param[in] pin1 Arduino digital pin number for motor pin 1. Defaults</span>
<a name="l00125"></a>00125 <span class="comment"> /// to pin 2. For a driver (pins==1), this is the Step input to the driver. Low to high transition means to step)</span>
<a name="l00126"></a>00126 <span class="comment"> /// \param[in] pin2 Arduino digital pin number for motor pin 2. Defaults</span>
<a name="l00127"></a>00127 <span class="comment"> /// to pin 3. For a driver (pins==1), this is the Direction input the driver. High means forward.</span>
<a name="l00128"></a>00128 <span class="comment"> /// \param[in] pin3 Arduino digital pin number for motor pin 3. Defaults</span>
<a name="l00129"></a>00129 <span class="comment"> /// to pin 4.</span>
<a name="l00130"></a>00130 <span class="comment"> /// \param[in] pin4 Arduino digital pin number for motor pin 4. Defaults</span>
<a name="l00131"></a>00131 <span class="comment"> /// to pin 5.</span>
<a name="l00132"></a>00132 <span class="comment"></span> <a class="code" href="classAccelStepper.html#a1290897df35915069e5eca9d034038c">AccelStepper</a>(uint8_t pins = 4, uint8_t pin1 = 2, uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5);
<a name="l00133"></a>00133 <span class="comment"></span>
<a name="l00134"></a>00134 <span class="comment"> /// Set the target position. The run() function will try to move the motor</span>
<a name="l00135"></a>00135 <span class="comment"> /// from the current position to the target position set by the most</span>
<a name="l00136"></a>00136 <span class="comment"> /// recent call to this function.</span>
<a name="l00137"></a>00137 <span class="comment"> /// \param[in] absolute The desired absolute position. Negative is</span>
<a name="l00138"></a>00138 <span class="comment"> /// anticlockwise from the 0 position.</span>
<a name="l00139"></a>00139 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#ce236ede35f87c63d18da25810ec9736">moveTo</a>(<span class="keywordtype">long</span> absolute);
<a name="l00140"></a>00140 <span class="comment"></span>
<a name="l00141"></a>00141 <span class="comment"> /// Set the target position relative to the current position</span>
<a name="l00142"></a>00142 <span class="comment"> /// \param[in] relative The desired position relative to the current position. Negative is</span>
<a name="l00143"></a>00143 <span class="comment"> /// anticlockwise from the current position.</span>
<a name="l00144"></a>00144 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#68942c66e78fb7f7b5f0cdade6eb7f06">move</a>(<span class="keywordtype">long</span> relative);
<a name="l00145"></a>00145 <span class="comment"></span>
<a name="l00146"></a>00146 <span class="comment"> /// Poll the motor and step it if a step is due, implementing</span>
<a name="l00147"></a>00147 <span class="comment"> /// accelerations and decelerations to achive the ratget position. You must call this as</span>
<a name="l00148"></a>00148 <span class="comment"> /// fequently as possible, but at least once per minimum step interval,</span>
<a name="l00149"></a>00149 <span class="comment"> /// preferably in your main loop.</span>
<a name="l00150"></a>00150 <span class="comment"> /// \return true if the motor is at the target position.</span>
<a name="l00151"></a>00151 <span class="comment"></span> <span class="keywordtype">boolean</span> <a class="code" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run</a>();
<a name="l00152"></a>00152 <span class="comment"></span>
<a name="l00153"></a>00153 <span class="comment"> /// Poll the motor and step it if a step is due, implmenting a constant</span>
<a name="l00154"></a>00154 <span class="comment"> /// speed as set by the most recent call to setSpeed().</span>
<a name="l00155"></a>00155 <span class="comment"> /// \return true if the motor was stepped.</span>
<a name="l00156"></a>00156 <span class="comment"></span> <span class="keywordtype">boolean</span> <a class="code" href="classAccelStepper.html#a4a6bdf99f698284faaeb5542b0b7514">runSpeed</a>();
<a name="l00157"></a>00157 <span class="comment"></span>
<a name="l00158"></a>00158 <span class="comment"> /// Sets the maximum permitted speed. the run() function will accelerate</span>
<a name="l00159"></a>00159 <span class="comment"> /// up to the speed set by this function.</span>
<a name="l00160"></a>00160 <span class="comment"> /// \param[in] speed The desired maximum speed in steps per second. Must</span>
<a name="l00161"></a>00161 <span class="comment"> /// be &gt; 0. Speeds of more than 1000 steps per second are unreliable. </span>
<a name="l00162"></a>00162 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#bee8d466229b87accba33d6ec929c18f">setMaxSpeed</a>(<span class="keywordtype">float</span> <a class="code" href="classAccelStepper.html#4f0989d0ae264e7eadfe1fa720769fb6">speed</a>);
<a name="l00163"></a>00163 <span class="comment"></span>
<a name="l00164"></a>00164 <span class="comment"> /// Sets the acceleration and deceleration parameter.</span>
<a name="l00165"></a>00165 <span class="comment"> /// \param[in] acceleration The desired acceleration in steps per second</span>
<a name="l00166"></a>00166 <span class="comment"> /// per second. Must be &gt; 0.</span>
<a name="l00167"></a>00167 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#dfb19e3cd2a028a1fe78131787604fd1">setAcceleration</a>(<span class="keywordtype">float</span> acceleration);
<a name="l00168"></a>00168 <span class="comment"></span>
<a name="l00169"></a>00169 <span class="comment"> /// Sets the desired constant speed for use with runSpeed().</span>
<a name="l00170"></a>00170 <span class="comment"> /// \param[in] speed The desired constant speed in steps per</span>
<a name="l00171"></a>00171 <span class="comment"> /// second. Positive is clockwise. Speeds of more than 1000 steps per</span>
<a name="l00172"></a>00172 <span class="comment"> /// second are unreliable. Very slow speeds may be set (eg 0.00027777 for</span>
<a name="l00173"></a>00173 <span class="comment"> /// once per hour, approximately. Speed accuracy depends on the Arduino</span>
<a name="l00174"></a>00174 <span class="comment"> /// crystal. Jitter depends on how frequently you call the runSpeed() function.</span>
<a name="l00175"></a>00175 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#e79c49ad69d5ccc9da0ee691fa4ca235">setSpeed</a>(<span class="keywordtype">float</span> speed);
<a name="l00176"></a>00176 <span class="comment"></span>
<a name="l00177"></a>00177 <span class="comment"> /// The most recently set speed</span>
<a name="l00178"></a>00178 <span class="comment"> /// \return the most recent speed in steps per second</span>
<a name="l00179"></a>00179 <span class="comment"></span> <span class="keywordtype">float</span> <a class="code" href="classAccelStepper.html#4f0989d0ae264e7eadfe1fa720769fb6">speed</a>();
<a name="l00180"></a>00180 <span class="comment"></span>
<a name="l00181"></a>00181 <span class="comment"> /// The distance from the current position to the target position.</span>
<a name="l00182"></a>00182 <span class="comment"> /// \return the distance from the current position to the target position</span>
<a name="l00183"></a>00183 <span class="comment"> /// in steps. Positive is clockwise from the current position.</span>
<a name="l00184"></a>00184 <span class="comment"></span> <span class="keywordtype">long</span> <a class="code" href="classAccelStepper.html#748665c3962e66fbc0e9373eb14c69c1">distanceToGo</a>();
<a name="l00185"></a>00185 <span class="comment"></span>
<a name="l00186"></a>00186 <span class="comment"> /// The most recently set target position.</span>
<a name="l00187"></a>00187 <span class="comment"> /// \return the target position</span>
<a name="l00188"></a>00188 <span class="comment"> /// in steps. Positive is clockwise from the 0 position.</span>
<a name="l00189"></a>00189 <span class="comment"></span> <span class="keywordtype">long</span> <a class="code" href="classAccelStepper.html#96685e0945b7cf75d5959da679cd911e">targetPosition</a>();
<a name="l00190"></a>00190
<a name="l00191"></a>00191 <span class="comment"></span>
<a name="l00192"></a>00192 <span class="comment"> /// The currently motor position.</span>
<a name="l00193"></a>00193 <span class="comment"> /// \return the current motor position</span>
<a name="l00194"></a>00194 <span class="comment"> /// in steps. Positive is clockwise from the 0 position.</span>
<a name="l00195"></a>00195 <span class="comment"></span> <span class="keywordtype">long</span> <a class="code" href="classAccelStepper.html#5dce13ab2a1b02b8f443318886bf6fc5">currentPosition</a>();
<a name="l00196"></a>00196 <span class="comment"></span>
<a name="l00197"></a>00197 <span class="comment"> /// Resets the current position of the motor, so that wherever the mottor</span>
<a name="l00198"></a>00198 <span class="comment"> /// happens to be right now is considered to be the new position. Useful</span>
<a name="l00199"></a>00199 <span class="comment"> /// for setting a zero position on a stepper after an initial hardware</span>
<a name="l00200"></a>00200 <span class="comment"> /// positioning move.</span>
<a name="l00201"></a>00201 <span class="comment"> /// \param[in] position The position in steps of wherever the motor</span>
<a name="l00202"></a>00202 <span class="comment"> /// happens to be right now.</span>
<a name="l00203"></a>00203 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#9d917f014317fb9d3b5dc14e66f6c689">setCurrentPosition</a>(<span class="keywordtype">long</span> position);
<a name="l00204"></a>00204 <span class="comment"></span>
<a name="l00205"></a>00205 <span class="comment"> /// Moves the motor to the target position and blocks until it is at</span>
<a name="l00206"></a>00206 <span class="comment"> /// position. Dont use this in event loops, since it blocks.</span>
<a name="l00207"></a>00207 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#344f58fef8cc34ac5aa75ba4b665d21c">runToPosition</a>();
<a name="l00208"></a>00208 <span class="comment"></span>
<a name="l00209"></a>00209 <span class="comment"> /// Runs at the currently selected speed until the target position is reached</span>
<a name="l00210"></a>00210 <span class="comment"> /// Does not implement accelerations.</span>
<a name="l00211"></a>00211 <span class="comment"></span> <span class="keywordtype">boolean</span> <a class="code" href="classAccelStepper.html#9270d20336e76ac1fd5bcd5b9c34f301">runSpeedToPosition</a>();
<a name="l00212"></a>00212 <span class="comment"></span>
<a name="l00213"></a>00213 <span class="comment"> /// Moves the motor to the new target position and blocks until it is at</span>
<a name="l00214"></a>00214 <span class="comment"> /// position. Dont use this in event loops, since it blocks.</span>
<a name="l00215"></a>00215 <span class="comment"> /// \param[in] position The new target position.</span>
<a name="l00216"></a>00216 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#176c5d2e4c2f21e9e92b12e39a6f0e67">runToNewPosition</a>(<span class="keywordtype">long</span> position);
<a name="l00217"></a>00217 <span class="comment"></span>
<a name="l00218"></a>00218 <span class="comment"> /// Disable motor pin outputs by setting them all LOW</span>
<a name="l00219"></a>00219 <span class="comment"> /// Depending on the design of your electronics this may turn off</span>
<a name="l00220"></a>00220 <span class="comment"> /// the power to the motor coils, saving power.</span>
<a name="l00221"></a>00221 <span class="comment"> /// This is useful to support Arduino low power modes: disable the outputs</span>
<a name="l00222"></a>00222 <span class="comment"> /// during sleep and then reenable with enableOutputs() before stepping</span>
<a name="l00223"></a>00223 <span class="comment"> /// again.</span>
<a name="l00224"></a>00224 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#3591e29a236e2935afd7f64ff6c22006">disableOutputs</a>();
<a name="l00225"></a>00225 <span class="comment"></span>
<a name="l00226"></a>00226 <span class="comment"> /// Enable motor pin outputs by setting the motor pins to OUTPUT</span>
<a name="l00227"></a>00227 <span class="comment"> /// mode. Called automatically by the constructor.</span>
<a name="l00228"></a>00228 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#a279a50d30d0413f570c692cff071643">enableOutputs</a>();
<a name="l00229"></a>00229
<a name="l00230"></a>00230 <span class="keyword">protected</span>:
<a name="l00231"></a>00231 <span class="comment"></span>
<a name="l00232"></a>00232 <span class="comment"> /// Forces the library to compute a new instantaneous speed and set that as</span>
<a name="l00233"></a>00233 <span class="comment"> /// the current speed. Calls</span>
<a name="l00234"></a>00234 <span class="comment"> /// desiredSpeed(), which can be overridden by subclasses. It is called by</span>
<a name="l00235"></a>00235 <span class="comment"> /// the library:</span>
<a name="l00236"></a>00236 <span class="comment"> /// \li after each step</span>
<a name="l00237"></a>00237 <span class="comment"> /// \li after change to maxSpeed through setMaxSpeed()</span>
<a name="l00238"></a>00238 <span class="comment"> /// \li after change to acceleration through setAcceleration()</span>
<a name="l00239"></a>00239 <span class="comment"> /// \li after change to target position (relative or absolute) through</span>
<a name="l00240"></a>00240 <span class="comment"> /// move() or moveTo()</span>
<a name="l00241"></a>00241 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#ffbee789b5c19165846cf0409860ae79">computeNewSpeed</a>();
<a name="l00242"></a>00242 <span class="comment"></span>
<a name="l00243"></a>00243 <span class="comment"> /// Called to execute a step. Only called when a new step is</span>
<a name="l00244"></a>00244 <span class="comment"> /// required. Subclasses may override to implement new stepping</span>
<a name="l00245"></a>00245 <span class="comment"> /// interfaces. The default calls step1(), step2() or step4() depending on the</span>
<a name="l00246"></a>00246 <span class="comment"> /// number of pins defined for the stepper.</span>
<a name="l00247"></a>00247 <span class="comment"> /// \param[in] step The current step phase number (0 to 3)</span>
<a name="l00248"></a>00248 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#3c9a220819d2451f79ff8a0c0a395b9f">step</a>(uint8_t <a class="code" href="classAccelStepper.html#3c9a220819d2451f79ff8a0c0a395b9f">step</a>);
<a name="l00249"></a>00249
<a name="l00250"></a>00250 <span class="comment"></span>
<a name="l00251"></a>00251 <span class="comment"> /// Called to execute a step on a stepper drover (ie where pins == 1). Only called when a new step is</span>
<a name="l00252"></a>00252 <span class="comment"> /// required. Subclasses may override to implement new stepping</span>
<a name="l00253"></a>00253 <span class="comment"> /// interfaces. The default sets or clears the outputs of Step pin1 to step, </span>
<a name="l00254"></a>00254 <span class="comment"> /// and sets the output of _pin2 to the desired direction. The Step pin (_pin1) is pulsed for 1 microsecond</span>
<a name="l00255"></a>00255 <span class="comment"> /// which is the minimum STEP pulse width for the 3967 driver.</span>
<a name="l00256"></a>00256 <span class="comment"> /// \param[in] step The current step phase number (0 to 3)</span>
<a name="l00257"></a>00257 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#cc64254ea242b53588e948335fd9305f">step1</a>(uint8_t step);
<a name="l00258"></a>00258 <span class="comment"></span>
<a name="l00259"></a>00259 <span class="comment"> /// Called to execute a step on a 2 pin motor. Only called when a new step is</span>
<a name="l00260"></a>00260 <span class="comment"> /// required. Subclasses may override to implement new stepping</span>
<a name="l00261"></a>00261 <span class="comment"> /// interfaces. The default sets or clears the outputs of pin1 and pin2</span>
<a name="l00262"></a>00262 <span class="comment"> /// \param[in] step The current step phase number (0 to 3)</span>
<a name="l00263"></a>00263 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#88f11bf6361fe002585f731d34fe2e8b">step2</a>(uint8_t step);
<a name="l00264"></a>00264 <span class="comment"></span>
<a name="l00265"></a>00265 <span class="comment"> /// Called to execute a step on a 4 pin motor. Only called when a new step is</span>
<a name="l00266"></a>00266 <span class="comment"> /// required. Subclasses may override to implement new stepping</span>
<a name="l00267"></a>00267 <span class="comment"> /// interfaces. The default sets or clears the outputs of pin1, pin2,</span>
<a name="l00268"></a>00268 <span class="comment"> /// pin3, pin4.</span>
<a name="l00269"></a>00269 <span class="comment"> /// \param[in] step The current step phase number (0 to 3)</span>
<a name="l00270"></a>00270 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classAccelStepper.html#49e448d179bbe4e0f8003a3f9993789d">step4</a>(uint8_t step);
<a name="l00271"></a>00271 <span class="comment"></span>
<a name="l00272"></a>00272 <span class="comment"> /// Compute and return the desired speed. The default algorithm uses</span>
<a name="l00273"></a>00273 <span class="comment"> /// maxSpeed, acceleration and the current speed to set a new speed to</span>
<a name="l00274"></a>00274 <span class="comment"> /// move the motor from teh current position to the target</span>
<a name="l00275"></a>00275 <span class="comment"> /// position. Subclasses may override this to provide an alternate</span>
<a name="l00276"></a>00276 <span class="comment"> /// algorithm (but do not block). Called by computeNewSpeed whenever a new speed neds to be</span>
<a name="l00277"></a>00277 <span class="comment"> /// computed. </span>
<a name="l00278"></a>00278 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">float</span> <a class="code" href="classAccelStepper.html#6e4bd79c395e69beee31d76d0d3287e4">desiredSpeed</a>();
<a name="l00279"></a>00279
<a name="l00280"></a>00280 <span class="keyword">private</span>:<span class="comment"></span>
<a name="l00281"></a>00281 <span class="comment"> /// Number of pins on the stepper motor. Permits 2 or 4. 2 pins is a</span>
<a name="l00282"></a>00282 <span class="comment"> /// bipolar, and 4 pins is a unipolar.</span>
<a name="l00283"></a>00283 <span class="comment"></span> uint8_t _pins; <span class="comment">// 2 or 4</span>
<a name="l00284"></a>00284 <span class="comment"></span>
<a name="l00285"></a>00285 <span class="comment"> /// Arduino pin number for the 2 or 4 pins required to interface to the</span>
<a name="l00286"></a>00286 <span class="comment"> /// stepper motor.</span>
<a name="l00287"></a>00287 <span class="comment"></span> uint8_t _pin1, _pin2, _pin3, _pin4;
<a name="l00288"></a>00288 <span class="comment"></span>
<a name="l00289"></a>00289 <span class="comment"> /// The current absolution position in steps.</span>
<a name="l00290"></a>00290 <span class="comment"></span> <span class="keywordtype">long</span> _currentPos; <span class="comment">// Steps</span>
<a name="l00291"></a>00291 <span class="comment"></span>
<a name="l00292"></a>00292 <span class="comment"> /// The target position in steps. The AccelStepper library will move the</span>
<a name="l00293"></a>00293 <span class="comment"> /// motor from teh _currentPos to the _targetPos, taking into account the</span>
<a name="l00294"></a>00294 <span class="comment"> /// max speed, acceleration and deceleration</span>
<a name="l00295"></a>00295 <span class="comment"></span> <span class="keywordtype">long</span> _targetPos; <span class="comment">// Steps</span>
<a name="l00296"></a>00296 <span class="comment"></span>
<a name="l00297"></a>00297 <span class="comment"> /// The current motos speed in steps per second</span>
<a name="l00298"></a>00298 <span class="comment"> /// Positive is clockwise</span>
<a name="l00299"></a>00299 <span class="comment"></span> <span class="keywordtype">float</span> _speed; <span class="comment">// Steps per second</span>
<a name="l00300"></a>00300 <span class="comment"></span>
<a name="l00301"></a>00301 <span class="comment"> /// The maximum permitted speed in steps per second. Must be &gt; 0.</span>
<a name="l00302"></a>00302 <span class="comment"></span> <span class="keywordtype">float</span> _maxSpeed;
<a name="l00303"></a>00303 <span class="comment"></span>
<a name="l00304"></a>00304 <span class="comment"> /// The acceleration to use to accelerate or decelerate the motor in steps</span>
<a name="l00305"></a>00305 <span class="comment"> /// per second per second. Must be &gt; 0</span>
<a name="l00306"></a>00306 <span class="comment"></span> <span class="keywordtype">float</span> _acceleration;
<a name="l00307"></a>00307 <span class="comment"></span>
<a name="l00308"></a>00308 <span class="comment"> /// The current interval between steps in milliseconds.</span>
<a name="l00309"></a>00309 <span class="comment"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> _stepInterval;
<a name="l00310"></a>00310 <span class="comment"></span>
<a name="l00311"></a>00311 <span class="comment"> /// The last step time in milliseconds</span>
<a name="l00312"></a>00312 <span class="comment"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> _lastStepTime;
<a name="l00313"></a>00313 };
<a name="l00314"></a>00314
<a name="l00315"></a>00315 <span class="preprocessor">#endif </span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

32
doc/annotated.html Normal file
View file

@ -0,0 +1,32 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: Class List</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li class="current"><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
<li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>Class List</h1>Here are the classes, structs, unions and interfaces with brief descriptions:<table>
<tr><td class="indexkey"><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td class="indexvalue">Support for stepper motors with acceleration etc </td></tr>
</table>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

View file

@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: Member List</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
<li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>AccelStepper Member List</h1>This is the complete list of members for <a class="el" href="classAccelStepper.html">AccelStepper</a>, including all inherited members.<p><table>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#a1290897df35915069e5eca9d034038c">AccelStepper</a>(uint8_t pins=4, uint8_t pin1=2, uint8_t pin2=3, uint8_t pin3=4, uint8_t pin4=5)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#ffbee789b5c19165846cf0409860ae79">computeNewSpeed</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td><code> [protected]</code></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#5dce13ab2a1b02b8f443318886bf6fc5">currentPosition</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#6e4bd79c395e69beee31d76d0d3287e4">desiredSpeed</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td><code> [protected, virtual]</code></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#3591e29a236e2935afd7f64ff6c22006">disableOutputs</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#748665c3962e66fbc0e9373eb14c69c1">distanceToGo</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#a279a50d30d0413f570c692cff071643">enableOutputs</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#68942c66e78fb7f7b5f0cdade6eb7f06">move</a>(long relative)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#ce236ede35f87c63d18da25810ec9736">moveTo</a>(long absolute)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#a4a6bdf99f698284faaeb5542b0b7514">runSpeed</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#9270d20336e76ac1fd5bcd5b9c34f301">runSpeedToPosition</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#176c5d2e4c2f21e9e92b12e39a6f0e67">runToNewPosition</a>(long position)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#344f58fef8cc34ac5aa75ba4b665d21c">runToPosition</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#dfb19e3cd2a028a1fe78131787604fd1">setAcceleration</a>(float acceleration)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#9d917f014317fb9d3b5dc14e66f6c689">setCurrentPosition</a>(long position)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#bee8d466229b87accba33d6ec929c18f">setMaxSpeed</a>(float speed)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#e79c49ad69d5ccc9da0ee691fa4ca235">setSpeed</a>(float speed)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#4f0989d0ae264e7eadfe1fa720769fb6">speed</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#3c9a220819d2451f79ff8a0c0a395b9f">step</a>(uint8_t step)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td><code> [protected, virtual]</code></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#cc64254ea242b53588e948335fd9305f">step1</a>(uint8_t step)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td><code> [protected, virtual]</code></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#88f11bf6361fe002585f731d34fe2e8b">step2</a>(uint8_t step)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td><code> [protected, virtual]</code></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#49e448d179bbe4e0f8003a3f9993789d">step4</a>(uint8_t step)</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td><code> [protected, virtual]</code></td></tr>
<tr class="memlist"><td><a class="el" href="classAccelStepper.html#96685e0945b7cf75d5959da679cd911e">targetPosition</a>()</td><td><a class="el" href="classAccelStepper.html">AccelStepper</a></td><td></td></tr>
</table></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

723
doc/classAccelStepper.html Normal file
View file

@ -0,0 +1,723 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: AccelStepper Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
<li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>AccelStepper Class Reference</h1><!-- doxytag: class="AccelStepper" -->Support for stepper motors with acceleration etc.
<a href="#_details">More...</a>
<p>
<code>#include &lt;<a class="el" href="AccelStepper_8h-source.html">AccelStepper.h</a>&gt;</code>
<p>
<p>
<a href="classAccelStepper-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#a1290897df35915069e5eca9d034038c">AccelStepper</a> (uint8_t pins=4, uint8_t pin1=2, uint8_t pin2=3, uint8_t pin3=4, uint8_t pin4=5)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#ce236ede35f87c63d18da25810ec9736">moveTo</a> (long absolute)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#68942c66e78fb7f7b5f0cdade6eb7f06">move</a> (long relative)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">boolean&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">boolean&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#a4a6bdf99f698284faaeb5542b0b7514">runSpeed</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#bee8d466229b87accba33d6ec929c18f">setMaxSpeed</a> (float speed)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#dfb19e3cd2a028a1fe78131787604fd1">setAcceleration</a> (float acceleration)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#e79c49ad69d5ccc9da0ee691fa4ca235">setSpeed</a> (float speed)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">float&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#4f0989d0ae264e7eadfe1fa720769fb6">speed</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">long&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#748665c3962e66fbc0e9373eb14c69c1">distanceToGo</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">long&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#96685e0945b7cf75d5959da679cd911e">targetPosition</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">long&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#5dce13ab2a1b02b8f443318886bf6fc5">currentPosition</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#9d917f014317fb9d3b5dc14e66f6c689">setCurrentPosition</a> (long position)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#344f58fef8cc34ac5aa75ba4b665d21c">runToPosition</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">boolean&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#9270d20336e76ac1fd5bcd5b9c34f301">runSpeedToPosition</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#176c5d2e4c2f21e9e92b12e39a6f0e67">runToNewPosition</a> (long position)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#3591e29a236e2935afd7f64ff6c22006">disableOutputs</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#a279a50d30d0413f570c692cff071643">enableOutputs</a> ()</td></tr>
<tr><td colspan="2"><br><h2>Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#ffbee789b5c19165846cf0409860ae79">computeNewSpeed</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#3c9a220819d2451f79ff8a0c0a395b9f">step</a> (uint8_t step)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#cc64254ea242b53588e948335fd9305f">step1</a> (uint8_t step)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#88f11bf6361fe002585f731d34fe2e8b">step2</a> (uint8_t step)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#49e448d179bbe4e0f8003a3f9993789d">step4</a> (uint8_t step)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual float&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classAccelStepper.html#6e4bd79c395e69beee31d76d0d3287e4">desiredSpeed</a> ()</td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
Support for stepper motors with acceleration etc.
<p>
This defines a single 2 or 4 pin stepper motor, or stepper moter with fdriver chip, with optional acceleration, deceleration, absolute positioning commands etc. Multiple simultaneous steppers are supported, all moving at different speeds and accelerations.<p>
<dl class="user" compact><dt><b>Operation</b></dt><dd>This module operates by computing a step time in milliseconds. The step time is recomputed after each step and after speed and acceleration parameters are changed by the caller. The time of each step is recorded in milliseconds. The <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run()</a> function steps the motor if a new step is due. The <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run()</a> function must be called frequently until the motor is in the desired position, after which time <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run()</a> will do nothing.</dd></dl>
<dl class="user" compact><dt><b>Positioning</b></dt><dd>Positions are specified by a signed long integer. At construction time, the current position of the motor is consider to be 0. Positive positions are clockwise from the initial position; negative positions are anticlockwise. The curent position can be altered for instance after initialization positioning.</dd></dl>
<dl class="user" compact><dt><b>Caveats</b></dt><dd>This is an open loop controller: If the motor stalls or is oversped, <a class="el" href="classAccelStepper.html" title="Support for stepper motors with acceleration etc.">AccelStepper</a> will not have a correct idea of where the motor really is (since there is no feedback of the motor's real position. We only know where we _think_ it is, relative to the initial starting point).</dd></dl>
The fastest motor speed that can be reliably supported is 1000 steps per second (1 step every millisecond). However any speed less than that down to very slow speeds (much less than one per second) are supported, provided the <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run()</a> function is called frequently enough to step the motor whenever required. <hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="a1290897df35915069e5eca9d034038c"></a><!-- doxytag: member="AccelStepper::AccelStepper" ref="a1290897df35915069e5eca9d034038c" args="(uint8_t pins=4, uint8_t pin1=2, uint8_t pin2=3, uint8_t pin3=4, uint8_t pin4=5)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">AccelStepper::AccelStepper </td>
<td>(</td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>pins</em> = <code>4</code>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>pin1</em> = <code>2</code>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>pin2</em> = <code>3</code>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>pin3</em> = <code>4</code>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>pin4</em> = <code>5</code></td><td>&nbsp;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Constructor. You can have multiple simultaneous steppers, all moving at different speeds and accelerations, provided you call their <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run()</a> functions at frequent enough intervals. Current Position is set to 0, target position is set to 0. MaxSpeed and Acceleration default to 1.0. The motor pins will be initialised to OUTPUT mode during the constructor by a call to <a class="el" href="classAccelStepper.html#a279a50d30d0413f570c692cff071643">enableOutputs()</a>. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>pins</em>&nbsp;</td><td>Number of pins to interface to. 1, 2 or 4 are supported. 1 means a stepper driver (with Step and Direction pins) 2 means a 2 wire stepper. 4 means a 4 wire stepper. Defaults to 4 pins. </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>pin1</em>&nbsp;</td><td>Arduino digital pin number for motor pin 1. Defaults to pin 2. For a driver (pins==1), this is the Step input to the driver. Low to high transition means to step) </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>pin2</em>&nbsp;</td><td>Arduino digital pin number for motor pin 2. Defaults to pin 3. For a driver (pins==1), this is the Direction input the driver. High means forward. </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>pin3</em>&nbsp;</td><td>Arduino digital pin number for motor pin 3. Defaults to pin 4. </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>pin4</em>&nbsp;</td><td>Arduino digital pin number for motor pin 4. Defaults to pin 5. </td></tr>
</table>
</dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00287">enableOutputs()</a>.</p>
</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="ce236ede35f87c63d18da25810ec9736"></a><!-- doxytag: member="AccelStepper::moveTo" ref="ce236ede35f87c63d18da25810ec9736" args="(long absolute)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::moveTo </td>
<td>(</td>
<td class="paramtype">long&nbsp;</td>
<td class="paramname"> <em>absolute</em> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Set the target position. The <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run()</a> function will try to move the motor from the current position to the target position set by the most recent call to this function. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>absolute</em>&nbsp;</td><td>The desired absolute position. Negative is anticlockwise from the 0 position. </td></tr>
</table>
</dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00069">computeNewSpeed()</a>.</p>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00015">move()</a>, and <a class="el" href="AccelStepper_8cpp-source.html#l00311">runToNewPosition()</a>.</p>
</div>
</div><p>
<a class="anchor" name="68942c66e78fb7f7b5f0cdade6eb7f06"></a><!-- doxytag: member="AccelStepper::move" ref="68942c66e78fb7f7b5f0cdade6eb7f06" args="(long relative)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::move </td>
<td>(</td>
<td class="paramtype">long&nbsp;</td>
<td class="paramname"> <em>relative</em> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Set the target position relative to the current position <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>relative</em>&nbsp;</td><td>The desired position relative to the current position. Negative is anticlockwise from the current position. </td></tr>
</table>
</dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00009">moveTo()</a>.</p>
</div>
</div><p>
<a class="anchor" name="608b2395b64ac15451d16d0371fe13ce"></a><!-- doxytag: member="AccelStepper::run" ref="608b2395b64ac15451d16d0371fe13ce" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">boolean AccelStepper::run </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Poll the motor and step it if a step is due, implementing accelerations and decelerations to achive the ratget position. You must call this as fequently as possible, but at least once per minimum step interval, preferably in your main loop. <dl class="return" compact><dt><b>Returns:</b></dt><dd>true if the motor is at the target position. </dd></dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00069">computeNewSpeed()</a>, and <a class="el" href="AccelStepper_8cpp-source.html#l00023">runSpeed()</a>.</p>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00299">runToPosition()</a>.</p>
</div>
</div><p>
<a class="anchor" name="a4a6bdf99f698284faaeb5542b0b7514"></a><!-- doxytag: member="AccelStepper::runSpeed" ref="a4a6bdf99f698284faaeb5542b0b7514" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">boolean AccelStepper::runSpeed </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Poll the motor and step it if a step is due, implmenting a constant speed as set by the most recent call to <a class="el" href="classAccelStepper.html#e79c49ad69d5ccc9da0ee691fa4ca235">setSpeed()</a>. <dl class="return" compact><dt><b>Returns:</b></dt><dd>true if the motor was stepped. </dd></dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00176">step()</a>.</p>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00125">run()</a>, and <a class="el" href="AccelStepper_8cpp-source.html#l00305">runSpeedToPosition()</a>.</p>
</div>
</div><p>
<a class="anchor" name="bee8d466229b87accba33d6ec929c18f"></a><!-- doxytag: member="AccelStepper::setMaxSpeed" ref="bee8d466229b87accba33d6ec929c18f" args="(float speed)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::setMaxSpeed </td>
<td>(</td>
<td class="paramtype">float&nbsp;</td>
<td class="paramname"> <em>speed</em> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Sets the maximum permitted speed. the <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">run()</a> function will accelerate up to the speed set by this function. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>speed</em>&nbsp;</td><td>The desired maximum speed in steps per second. Must be &gt; 0. Speeds of more than 1000 steps per second are unreliable. </td></tr>
</table>
</dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00069">computeNewSpeed()</a>.</p>
</div>
</div><p>
<a class="anchor" name="dfb19e3cd2a028a1fe78131787604fd1"></a><!-- doxytag: member="AccelStepper::setAcceleration" ref="dfb19e3cd2a028a1fe78131787604fd1" args="(float acceleration)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::setAcceleration </td>
<td>(</td>
<td class="paramtype">float&nbsp;</td>
<td class="paramname"> <em>acceleration</em> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Sets the acceleration and deceleration parameter. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>acceleration</em>&nbsp;</td><td>The desired acceleration in steps per second per second. Must be &gt; 0. </td></tr>
</table>
</dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00069">computeNewSpeed()</a>.</p>
</div>
</div><p>
<a class="anchor" name="e79c49ad69d5ccc9da0ee691fa4ca235"></a><!-- doxytag: member="AccelStepper::setSpeed" ref="e79c49ad69d5ccc9da0ee691fa4ca235" args="(float speed)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::setSpeed </td>
<td>(</td>
<td class="paramtype">float&nbsp;</td>
<td class="paramname"> <em>speed</em> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Sets the desired constant speed for use with <a class="el" href="classAccelStepper.html#a4a6bdf99f698284faaeb5542b0b7514">runSpeed()</a>. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>speed</em>&nbsp;</td><td>The desired constant speed in steps per second. Positive is clockwise. Speeds of more than 1000 steps per second are unreliable. Very slow speeds may be set (eg 0.00027777 for once per hour, approximately. Speed accuracy depends on the Arduino crystal. Jitter depends on how frequently you call the <a class="el" href="classAccelStepper.html#a4a6bdf99f698284faaeb5542b0b7514">runSpeed()</a> function. </td></tr>
</table>
</dl>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00069">computeNewSpeed()</a>.</p>
</div>
</div><p>
<a class="anchor" name="4f0989d0ae264e7eadfe1fa720769fb6"></a><!-- doxytag: member="AccelStepper::speed" ref="4f0989d0ae264e7eadfe1fa720769fb6" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">float AccelStepper::speed </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
The most recently set speed <dl class="return" compact><dt><b>Returns:</b></dt><dd>the most recent speed in steps per second </dd></dl>
</div>
</div><p>
<a class="anchor" name="748665c3962e66fbc0e9373eb14c69c1"></a><!-- doxytag: member="AccelStepper::distanceToGo" ref="748665c3962e66fbc0e9373eb14c69c1" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">long AccelStepper::distanceToGo </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
The distance from the current position to the target position. <dl class="return" compact><dt><b>Returns:</b></dt><dd>the distance from the current position to the target position in steps. Positive is clockwise from the current position. </dd></dl>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00084">desiredSpeed()</a>.</p>
</div>
</div><p>
<a class="anchor" name="96685e0945b7cf75d5959da679cd911e"></a><!-- doxytag: member="AccelStepper::targetPosition" ref="96685e0945b7cf75d5959da679cd911e" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">long AccelStepper::targetPosition </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
The most recently set target position. <dl class="return" compact><dt><b>Returns:</b></dt><dd>the target position in steps. Positive is clockwise from the 0 position. </dd></dl>
</div>
</div><p>
<a class="anchor" name="5dce13ab2a1b02b8f443318886bf6fc5"></a><!-- doxytag: member="AccelStepper::currentPosition" ref="5dce13ab2a1b02b8f443318886bf6fc5" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">long AccelStepper::currentPosition </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
The currently motor position. <dl class="return" compact><dt><b>Returns:</b></dt><dd>the current motor position in steps. Positive is clockwise from the 0 position. </dd></dl>
</div>
</div><p>
<a class="anchor" name="9d917f014317fb9d3b5dc14e66f6c689"></a><!-- doxytag: member="AccelStepper::setCurrentPosition" ref="9d917f014317fb9d3b5dc14e66f6c689" args="(long position)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::setCurrentPosition </td>
<td>(</td>
<td class="paramtype">long&nbsp;</td>
<td class="paramname"> <em>position</em> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Resets the current position of the motor, so that wherever the mottor happens to be right now is considered to be the new position. Useful for setting a zero position on a stepper after an initial hardware positioning move. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>position</em>&nbsp;</td><td>The position in steps of wherever the motor happens to be right now. </td></tr>
</table>
</dl>
</div>
</div><p>
<a class="anchor" name="344f58fef8cc34ac5aa75ba4b665d21c"></a><!-- doxytag: member="AccelStepper::runToPosition" ref="344f58fef8cc34ac5aa75ba4b665d21c" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::runToPosition </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Moves the motor to the target position and blocks until it is at position. Dont use this in event loops, since it blocks.
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00125">run()</a>.</p>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00311">runToNewPosition()</a>.</p>
</div>
</div><p>
<a class="anchor" name="9270d20336e76ac1fd5bcd5b9c34f301"></a><!-- doxytag: member="AccelStepper::runSpeedToPosition" ref="9270d20336e76ac1fd5bcd5b9c34f301" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">boolean AccelStepper::runSpeedToPosition </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Runs at the currently selected speed until the target position is reached Does not implement accelerations.
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00023">runSpeed()</a>.</p>
</div>
</div><p>
<a class="anchor" name="176c5d2e4c2f21e9e92b12e39a6f0e67"></a><!-- doxytag: member="AccelStepper::runToNewPosition" ref="176c5d2e4c2f21e9e92b12e39a6f0e67" args="(long position)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::runToNewPosition </td>
<td>(</td>
<td class="paramtype">long&nbsp;</td>
<td class="paramname"> <em>position</em> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Moves the motor to the new target position and blocks until it is at position. Dont use this in event loops, since it blocks. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>position</em>&nbsp;</td><td>The new target position. </td></tr>
</table>
</dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00009">moveTo()</a>, and <a class="el" href="AccelStepper_8cpp-source.html#l00299">runToPosition()</a>.</p>
</div>
</div><p>
<a class="anchor" name="3591e29a236e2935afd7f64ff6c22006"></a><!-- doxytag: member="AccelStepper::disableOutputs" ref="3591e29a236e2935afd7f64ff6c22006" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::disableOutputs </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Disable motor pin outputs by setting them all LOW Depending on the design of your electronics this may turn off the power to the motor coils, saving power. This is useful to support Arduino low power modes: disable the outputs during sleep and then reenable with <a class="el" href="classAccelStepper.html#a279a50d30d0413f570c692cff071643">enableOutputs()</a> before stepping again.
</div>
</div><p>
<a class="anchor" name="a279a50d30d0413f570c692cff071643"></a><!-- doxytag: member="AccelStepper::enableOutputs" ref="a279a50d30d0413f570c692cff071643" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::enableOutputs </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Enable motor pin outputs by setting the motor pins to OUTPUT mode. Called automatically by the constructor.
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00135">AccelStepper()</a>.</p>
</div>
</div><p>
<a class="anchor" name="ffbee789b5c19165846cf0409860ae79"></a><!-- doxytag: member="AccelStepper::computeNewSpeed" ref="ffbee789b5c19165846cf0409860ae79" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::computeNewSpeed </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td><code> [protected]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Forces the library to compute a new instantaneous speed and set that as the current speed. Calls <a class="el" href="classAccelStepper.html#6e4bd79c395e69beee31d76d0d3287e4">desiredSpeed()</a>, which can be overridden by subclasses. It is called by the library: <ul>
<li>after each step </li>
<li>after change to maxSpeed through <a class="el" href="classAccelStepper.html#bee8d466229b87accba33d6ec929c18f">setMaxSpeed()</a> </li>
<li>after change to acceleration through <a class="el" href="classAccelStepper.html#dfb19e3cd2a028a1fe78131787604fd1">setAcceleration()</a> </li>
<li>after change to target position (relative or absolute) through <a class="el" href="classAccelStepper.html#68942c66e78fb7f7b5f0cdade6eb7f06">move()</a> or <a class="el" href="classAccelStepper.html#ce236ede35f87c63d18da25810ec9736">moveTo()</a> </li>
</ul>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00084">desiredSpeed()</a>, and <a class="el" href="AccelStepper_8cpp-source.html#l00164">setSpeed()</a>.</p>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00009">moveTo()</a>, <a class="el" href="AccelStepper_8cpp-source.html#l00125">run()</a>, <a class="el" href="AccelStepper_8cpp-source.html#l00158">setAcceleration()</a>, and <a class="el" href="AccelStepper_8cpp-source.html#l00152">setMaxSpeed()</a>.</p>
</div>
</div><p>
<a class="anchor" name="3c9a220819d2451f79ff8a0c0a395b9f"></a><!-- doxytag: member="AccelStepper::step" ref="3c9a220819d2451f79ff8a0c0a395b9f" args="(uint8_t step)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::step </td>
<td>(</td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>step</em> </td>
<td>&nbsp;)&nbsp;</td>
<td><code> [protected, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Called to execute a step. Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default calls <a class="el" href="classAccelStepper.html#cc64254ea242b53588e948335fd9305f">step1()</a>, <a class="el" href="classAccelStepper.html#88f11bf6361fe002585f731d34fe2e8b">step2()</a> or <a class="el" href="classAccelStepper.html#49e448d179bbe4e0f8003a3f9993789d">step4()</a> depending on the number of pins defined for the stepper. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>step</em>&nbsp;</td><td>The current step phase number (0 to 3) </td></tr>
</table>
</dl>
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00197">step1()</a>, <a class="el" href="AccelStepper_8cpp-source.html#l00211">step2()</a>, and <a class="el" href="AccelStepper_8cpp-source.html#l00240">step4()</a>.</p>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00023">runSpeed()</a>.</p>
</div>
</div><p>
<a class="anchor" name="cc64254ea242b53588e948335fd9305f"></a><!-- doxytag: member="AccelStepper::step1" ref="cc64254ea242b53588e948335fd9305f" args="(uint8_t step)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::step1 </td>
<td>(</td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>step</em> </td>
<td>&nbsp;)&nbsp;</td>
<td><code> [protected, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Called to execute a step on a stepper drover (ie where pins == 1). Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default sets or clears the outputs of Step pin1 to step, and sets the output of _pin2 to the desired direction. The Step pin (_pin1) is pulsed for 1 microsecond which is the minimum STEP pulse width for the 3967 driver. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>step</em>&nbsp;</td><td>The current step phase number (0 to 3) </td></tr>
</table>
</dl>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00176">step()</a>.</p>
</div>
</div><p>
<a class="anchor" name="88f11bf6361fe002585f731d34fe2e8b"></a><!-- doxytag: member="AccelStepper::step2" ref="88f11bf6361fe002585f731d34fe2e8b" args="(uint8_t step)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::step2 </td>
<td>(</td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>step</em> </td>
<td>&nbsp;)&nbsp;</td>
<td><code> [protected, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Called to execute a step on a 2 pin motor. Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default sets or clears the outputs of pin1 and pin2 <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>step</em>&nbsp;</td><td>The current step phase number (0 to 3) </td></tr>
</table>
</dl>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00176">step()</a>.</p>
</div>
</div><p>
<a class="anchor" name="49e448d179bbe4e0f8003a3f9993789d"></a><!-- doxytag: member="AccelStepper::step4" ref="49e448d179bbe4e0f8003a3f9993789d" args="(uint8_t step)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void AccelStepper::step4 </td>
<td>(</td>
<td class="paramtype">uint8_t&nbsp;</td>
<td class="paramname"> <em>step</em> </td>
<td>&nbsp;)&nbsp;</td>
<td><code> [protected, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Called to execute a step on a 4 pin motor. Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default sets or clears the outputs of pin1, pin2, pin3, pin4. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>step</em>&nbsp;</td><td>The current step phase number (0 to 3) </td></tr>
</table>
</dl>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00176">step()</a>.</p>
</div>
</div><p>
<a class="anchor" name="6e4bd79c395e69beee31d76d0d3287e4"></a><!-- doxytag: member="AccelStepper::desiredSpeed" ref="6e4bd79c395e69beee31d76d0d3287e4" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">float AccelStepper::desiredSpeed </td>
<td>(</td>
<td class="paramname"> </td>
<td>&nbsp;)&nbsp;</td>
<td><code> [protected, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Compute and return the desired speed. The default algorithm uses maxSpeed, acceleration and the current speed to set a new speed to move the motor from teh current position to the target position. Subclasses may override this to provide an alternate algorithm (but do not block). Called by computeNewSpeed whenever a new speed neds to be computed.
<p>References <a class="el" href="AccelStepper_8cpp-source.html#l00048">distanceToGo()</a>.</p>
<p>Referenced by <a class="el" href="AccelStepper_8cpp-source.html#l00069">computeNewSpeed()</a>.</p>
</div>
</div><p>
<hr>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="AccelStepper_8h-source.html">AccelStepper.h</a><li>AccelStepper.cpp</ul>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

473
doc/doxygen.css Normal file
View file

@ -0,0 +1,473 @@
BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
font-family: Geneva, Arial, Helvetica, sans-serif;
}
BODY,TD {
font-size: 90%;
}
H1 {
text-align: center;
font-size: 160%;
}
H2 {
font-size: 120%;
}
H3 {
font-size: 100%;
}
CAPTION {
font-weight: bold
}
DIV.qindex {
width: 100%;
background-color: #e8eef2;
border: 1px solid #84b0c7;
text-align: center;
margin: 2px;
padding: 2px;
line-height: 140%;
}
DIV.navpath {
width: 100%;
background-color: #e8eef2;
border: 1px solid #84b0c7;
text-align: center;
margin: 2px;
padding: 2px;
line-height: 140%;
}
DIV.navtab {
background-color: #e8eef2;
border: 1px solid #84b0c7;
text-align: center;
margin: 2px;
margin-right: 15px;
padding: 2px;
}
TD.navtab {
font-size: 70%;
}
A.qindex {
text-decoration: none;
font-weight: bold;
color: #1A419D;
}
A.qindex:visited {
text-decoration: none;
font-weight: bold;
color: #1A419D
}
A.qindex:hover {
text-decoration: none;
background-color: #ddddff;
}
A.qindexHL {
text-decoration: none;
font-weight: bold;
background-color: #6666cc;
color: #ffffff;
border: 1px double #9295C2;
}
A.qindexHL:hover {
text-decoration: none;
background-color: #6666cc;
color: #ffffff;
}
A.qindexHL:visited {
text-decoration: none;
background-color: #6666cc;
color: #ffffff
}
A.el {
text-decoration: none;
font-weight: bold
}
A.elRef {
font-weight: bold
}
A.code:link {
text-decoration: none;
font-weight: normal;
color: #0000FF
}
A.code:visited {
text-decoration: none;
font-weight: normal;
color: #0000FF
}
A.codeRef:link {
font-weight: normal;
color: #0000FF
}
A.codeRef:visited {
font-weight: normal;
color: #0000FF
}
A:hover {
text-decoration: none;
background-color: #f2f2ff
}
DL.el {
margin-left: -1cm
}
.fragment {
font-family: monospace, fixed;
font-size: 95%;
}
PRE.fragment {
border: 1px solid #CCCCCC;
background-color: #f5f5f5;
margin-top: 4px;
margin-bottom: 4px;
margin-left: 2px;
margin-right: 8px;
padding-left: 6px;
padding-right: 6px;
padding-top: 4px;
padding-bottom: 4px;
}
DIV.ah {
background-color: black;
font-weight: bold;
color: #ffffff;
margin-bottom: 3px;
margin-top: 3px
}
DIV.groupHeader {
margin-left: 16px;
margin-top: 12px;
margin-bottom: 6px;
font-weight: bold;
}
DIV.groupText {
margin-left: 16px;
font-style: italic;
font-size: 90%
}
BODY {
background: white;
color: black;
margin-right: 20px;
margin-left: 20px;
}
TD.indexkey {
background-color: #e8eef2;
font-weight: bold;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px;
border: 1px solid #CCCCCC;
}
TD.indexvalue {
background-color: #e8eef2;
font-style: italic;
padding-right : 10px;
padding-top : 2px;
padding-left : 10px;
padding-bottom : 2px;
margin-left : 0px;
margin-right : 0px;
margin-top : 2px;
margin-bottom : 2px;
border: 1px solid #CCCCCC;
}
TR.memlist {
background-color: #f0f0f0;
}
P.formulaDsp {
text-align: center;
}
IMG.formulaDsp {
}
IMG.formulaInl {
vertical-align: middle;
}
SPAN.keyword { color: #008000 }
SPAN.keywordtype { color: #604020 }
SPAN.keywordflow { color: #e08000 }
SPAN.comment { color: #800000 }
SPAN.preprocessor { color: #806020 }
SPAN.stringliteral { color: #002080 }
SPAN.charliteral { color: #008080 }
SPAN.vhdldigit { color: #ff00ff }
SPAN.vhdlchar { color: #000000 }
SPAN.vhdlkeyword { color: #700070 }
SPAN.vhdllogic { color: #ff0000 }
.mdescLeft {
padding: 0px 8px 4px 8px;
font-size: 80%;
font-style: italic;
background-color: #FAFAFA;
border-top: 1px none #E0E0E0;
border-right: 1px none #E0E0E0;
border-bottom: 1px none #E0E0E0;
border-left: 1px none #E0E0E0;
margin: 0px;
}
.mdescRight {
padding: 0px 8px 4px 8px;
font-size: 80%;
font-style: italic;
background-color: #FAFAFA;
border-top: 1px none #E0E0E0;
border-right: 1px none #E0E0E0;
border-bottom: 1px none #E0E0E0;
border-left: 1px none #E0E0E0;
margin: 0px;
}
.memItemLeft {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memItemRight {
padding: 1px 8px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplItemLeft {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplItemRight {
padding: 1px 8px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
}
.memTemplParams {
padding: 1px 0px 0px 8px;
margin: 4px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #E0E0E0;
border-right-color: #E0E0E0;
border-bottom-color: #E0E0E0;
border-left-color: #E0E0E0;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
color: #606060;
background-color: #FAFAFA;
font-size: 80%;
}
.search {
color: #003399;
font-weight: bold;
}
FORM.search {
margin-bottom: 0px;
margin-top: 0px;
}
INPUT.search {
font-size: 75%;
color: #000080;
font-weight: normal;
background-color: #e8eef2;
}
TD.tiny {
font-size: 75%;
}
a {
color: #1A41A8;
}
a:visited {
color: #2A3798;
}
.dirtab {
padding: 4px;
border-collapse: collapse;
border: 1px solid #84b0c7;
}
TH.dirtab {
background: #e8eef2;
font-weight: bold;
}
HR {
height: 1px;
border: none;
border-top: 1px solid black;
}
/* Style for detailed member documentation */
.memtemplate {
font-size: 80%;
color: #606060;
font-weight: normal;
margin-left: 3px;
}
.memnav {
background-color: #e8eef2;
border: 1px solid #84b0c7;
text-align: center;
margin: 2px;
margin-right: 15px;
padding: 2px;
}
.memitem {
padding: 4px;
background-color: #eef3f5;
border-width: 1px;
border-style: solid;
border-color: #dedeee;
-moz-border-radius: 8px 8px 8px 8px;
}
.memname {
white-space: nowrap;
font-weight: bold;
}
.memdoc{
padding-left: 10px;
}
.memproto {
background-color: #d5e1e8;
width: 100%;
border-width: 1px;
border-style: solid;
border-color: #84b0c7;
font-weight: bold;
-moz-border-radius: 8px 8px 8px 8px;
}
.paramkey {
text-align: right;
}
.paramtype {
white-space: nowrap;
}
.paramname {
color: #602020;
font-style: italic;
white-space: nowrap;
}
/* End Styling for detailed member documentation */
/* for the tree view */
.ftvtree {
font-family: sans-serif;
margin:0.5em;
}
/* these are for tree view when used as main index */
.directory {
font-size: 9pt;
font-weight: bold;
}
.directory h3 {
margin: 0px;
margin-top: 1em;
font-size: 11pt;
}
/* The following two styles can be used to replace the root node title */
/* with an image of your choice. Simply uncomment the next two styles, */
/* specify the name of your image and be sure to set 'height' to the */
/* proper pixel height of your image. */
/* .directory h3.swap { */
/* height: 61px; */
/* background-repeat: no-repeat; */
/* background-image: url("yourimage.gif"); */
/* } */
/* .directory h3.swap span { */
/* display: none; */
/* } */
.directory > h3 {
margin-top: 0;
}
.directory p {
margin: 0px;
white-space: nowrap;
}
.directory div {
display: none;
margin: 0px;
}
.directory img {
vertical-align: -30%;
}
/* these are for tree view when not used as main index */
.directory-alt {
font-size: 100%;
font-weight: bold;
}
.directory-alt h3 {
margin: 0px;
margin-top: 1em;
font-size: 11pt;
}
.directory-alt > h3 {
margin-top: 0;
}
.directory-alt p {
margin: 0px;
white-space: nowrap;
}
.directory-alt div {
display: none;
margin: 0px;
}
.directory-alt img {
vertical-align: -30%;
}

BIN
doc/doxygen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

26
doc/files.html Normal file
View file

@ -0,0 +1,26 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: File Index</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>File List</h1>Here is a list of all documented files with brief descriptions:<table>
<tr><td class="indexkey"><b>AccelStepper.h</b> <a href="AccelStepper_8h-source.html">[code]</a></td><td class="indexvalue"></td></tr>
</table>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

87
doc/functions.html Normal file
View file

@ -0,0 +1,87 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: Class Members</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
<li class="current"><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li class="current"><a href="functions.html"><span>All</span></a></li>
<li><a href="functions_func.html"><span>Functions</span></a></li>
</ul>
</div>
</div>
<div class="contents">
Here is a list of all documented class members with links to the class documentation for each member:
<p>
<ul>
<li>AccelStepper()
: <a class="el" href="classAccelStepper.html#a1290897df35915069e5eca9d034038c">AccelStepper</a>
<li>computeNewSpeed()
: <a class="el" href="classAccelStepper.html#ffbee789b5c19165846cf0409860ae79">AccelStepper</a>
<li>currentPosition()
: <a class="el" href="classAccelStepper.html#5dce13ab2a1b02b8f443318886bf6fc5">AccelStepper</a>
<li>desiredSpeed()
: <a class="el" href="classAccelStepper.html#6e4bd79c395e69beee31d76d0d3287e4">AccelStepper</a>
<li>disableOutputs()
: <a class="el" href="classAccelStepper.html#3591e29a236e2935afd7f64ff6c22006">AccelStepper</a>
<li>distanceToGo()
: <a class="el" href="classAccelStepper.html#748665c3962e66fbc0e9373eb14c69c1">AccelStepper</a>
<li>enableOutputs()
: <a class="el" href="classAccelStepper.html#a279a50d30d0413f570c692cff071643">AccelStepper</a>
<li>move()
: <a class="el" href="classAccelStepper.html#68942c66e78fb7f7b5f0cdade6eb7f06">AccelStepper</a>
<li>moveTo()
: <a class="el" href="classAccelStepper.html#ce236ede35f87c63d18da25810ec9736">AccelStepper</a>
<li>run()
: <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">AccelStepper</a>
<li>runSpeed()
: <a class="el" href="classAccelStepper.html#a4a6bdf99f698284faaeb5542b0b7514">AccelStepper</a>
<li>runSpeedToPosition()
: <a class="el" href="classAccelStepper.html#9270d20336e76ac1fd5bcd5b9c34f301">AccelStepper</a>
<li>runToNewPosition()
: <a class="el" href="classAccelStepper.html#176c5d2e4c2f21e9e92b12e39a6f0e67">AccelStepper</a>
<li>runToPosition()
: <a class="el" href="classAccelStepper.html#344f58fef8cc34ac5aa75ba4b665d21c">AccelStepper</a>
<li>setAcceleration()
: <a class="el" href="classAccelStepper.html#dfb19e3cd2a028a1fe78131787604fd1">AccelStepper</a>
<li>setCurrentPosition()
: <a class="el" href="classAccelStepper.html#9d917f014317fb9d3b5dc14e66f6c689">AccelStepper</a>
<li>setMaxSpeed()
: <a class="el" href="classAccelStepper.html#bee8d466229b87accba33d6ec929c18f">AccelStepper</a>
<li>setSpeed()
: <a class="el" href="classAccelStepper.html#e79c49ad69d5ccc9da0ee691fa4ca235">AccelStepper</a>
<li>speed()
: <a class="el" href="classAccelStepper.html#4f0989d0ae264e7eadfe1fa720769fb6">AccelStepper</a>
<li>step()
: <a class="el" href="classAccelStepper.html#3c9a220819d2451f79ff8a0c0a395b9f">AccelStepper</a>
<li>step1()
: <a class="el" href="classAccelStepper.html#cc64254ea242b53588e948335fd9305f">AccelStepper</a>
<li>step2()
: <a class="el" href="classAccelStepper.html#88f11bf6361fe002585f731d34fe2e8b">AccelStepper</a>
<li>step4()
: <a class="el" href="classAccelStepper.html#49e448d179bbe4e0f8003a3f9993789d">AccelStepper</a>
<li>targetPosition()
: <a class="el" href="classAccelStepper.html#96685e0945b7cf75d5959da679cd911e">AccelStepper</a>
</ul>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

87
doc/functions_func.html Normal file
View file

@ -0,0 +1,87 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: Class Members - Functions</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
<li class="current"><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="functions.html"><span>All</span></a></li>
<li class="current"><a href="functions_func.html"><span>Functions</span></a></li>
</ul>
</div>
</div>
<div class="contents">
&nbsp;
<p>
<ul>
<li>AccelStepper()
: <a class="el" href="classAccelStepper.html#a1290897df35915069e5eca9d034038c">AccelStepper</a>
<li>computeNewSpeed()
: <a class="el" href="classAccelStepper.html#ffbee789b5c19165846cf0409860ae79">AccelStepper</a>
<li>currentPosition()
: <a class="el" href="classAccelStepper.html#5dce13ab2a1b02b8f443318886bf6fc5">AccelStepper</a>
<li>desiredSpeed()
: <a class="el" href="classAccelStepper.html#6e4bd79c395e69beee31d76d0d3287e4">AccelStepper</a>
<li>disableOutputs()
: <a class="el" href="classAccelStepper.html#3591e29a236e2935afd7f64ff6c22006">AccelStepper</a>
<li>distanceToGo()
: <a class="el" href="classAccelStepper.html#748665c3962e66fbc0e9373eb14c69c1">AccelStepper</a>
<li>enableOutputs()
: <a class="el" href="classAccelStepper.html#a279a50d30d0413f570c692cff071643">AccelStepper</a>
<li>move()
: <a class="el" href="classAccelStepper.html#68942c66e78fb7f7b5f0cdade6eb7f06">AccelStepper</a>
<li>moveTo()
: <a class="el" href="classAccelStepper.html#ce236ede35f87c63d18da25810ec9736">AccelStepper</a>
<li>run()
: <a class="el" href="classAccelStepper.html#608b2395b64ac15451d16d0371fe13ce">AccelStepper</a>
<li>runSpeed()
: <a class="el" href="classAccelStepper.html#a4a6bdf99f698284faaeb5542b0b7514">AccelStepper</a>
<li>runSpeedToPosition()
: <a class="el" href="classAccelStepper.html#9270d20336e76ac1fd5bcd5b9c34f301">AccelStepper</a>
<li>runToNewPosition()
: <a class="el" href="classAccelStepper.html#176c5d2e4c2f21e9e92b12e39a6f0e67">AccelStepper</a>
<li>runToPosition()
: <a class="el" href="classAccelStepper.html#344f58fef8cc34ac5aa75ba4b665d21c">AccelStepper</a>
<li>setAcceleration()
: <a class="el" href="classAccelStepper.html#dfb19e3cd2a028a1fe78131787604fd1">AccelStepper</a>
<li>setCurrentPosition()
: <a class="el" href="classAccelStepper.html#9d917f014317fb9d3b5dc14e66f6c689">AccelStepper</a>
<li>setMaxSpeed()
: <a class="el" href="classAccelStepper.html#bee8d466229b87accba33d6ec929c18f">AccelStepper</a>
<li>setSpeed()
: <a class="el" href="classAccelStepper.html#e79c49ad69d5ccc9da0ee691fa4ca235">AccelStepper</a>
<li>speed()
: <a class="el" href="classAccelStepper.html#4f0989d0ae264e7eadfe1fa720769fb6">AccelStepper</a>
<li>step()
: <a class="el" href="classAccelStepper.html#3c9a220819d2451f79ff8a0c0a395b9f">AccelStepper</a>
<li>step1()
: <a class="el" href="classAccelStepper.html#cc64254ea242b53588e948335fd9305f">AccelStepper</a>
<li>step2()
: <a class="el" href="classAccelStepper.html#88f11bf6361fe002585f731d34fe2e8b">AccelStepper</a>
<li>step4()
: <a class="el" href="classAccelStepper.html#49e448d179bbe4e0f8003a3f9993789d">AccelStepper</a>
<li>targetPosition()
: <a class="el" href="classAccelStepper.html#96685e0945b7cf75d5959da679cd911e">AccelStepper</a>
</ul>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

51
doc/index.html Normal file
View file

@ -0,0 +1,51 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AccelStepper: AccelStepper library for Arduino</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li class="current"><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>AccelStepper library for Arduino</h1>
<p>
This is the Arduino <a class="el" href="classAccelStepper.html" title="Support for stepper motors with acceleration etc.">AccelStepper</a> 1.2 library. It provides an object-oriented interface for 2 or 4 pin stepper motors.<p>
The standard Arduino IDE includes the Stepper library (<a href="http://arduino.cc/en/Reference/Stepper">http://arduino.cc/en/Reference/Stepper</a>) for stepper motors. It is perfectly adequate for simple, single motor applications.<p>
<a class="el" href="classAccelStepper.html" title="Support for stepper motors with acceleration etc.">AccelStepper</a> significantly improves on the standard Arduino Stepper library in several ways: <ul>
<li>Supports acceleration and deceleration </li>
<li>Supports multiple simultaneous steppers, with independent concurrent stepping on each stepper </li>
<li>API functions never delay() or block </li>
<li>Supports 2 and 4 wire steppers </li>
<li>Supports stepper drivers such as the Sparkfun EasyDriver (based on 3967 driver chip) </li>
<li>Very slow speeds are supported </li>
<li>Extensive API </li>
<li>Subclass support</li>
</ul>
The latest version of this documentation can be downloaded from <a href="http://www.open.com.au/mikem/arduino/AccelStepper">http://www.open.com.au/mikem/arduino/AccelStepper</a><p>
Example Arduino programs are included to show the main modes of use.<p>
The version of the package that this documentation refers to can be downloaded from <a href="http://www.open.com.au/mikem/arduino/AccelStepper/AccelStepper-1.3.zip">http://www.open.com.au/mikem/arduino/AccelStepper/AccelStepper-1.3.zip</a> You can find the latest version at <a href="http://www.open.com.au/mikem/arduino/AccelStepper">http://www.open.com.au/mikem/arduino/AccelStepper</a><p>
Tested on Arduino Diecimila and Mega with arduino-0018 on OpenSuSE 11.1 and avr-libc-1.6.1-1.15, cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5.<p>
<dl class="user" compact><dt><b>Installation</b></dt><dd>Install in the usual way: unzip the distribution zip file to the libraries sub-folder of your sketchbook.</dd></dl>
This software is Copyright (C) 2010 Mike McCauley. Use is subject to license conditions. The main licensing options available are GPL V2 or Commercial:<p>
<dl class="user" compact><dt><b>Open Source Licensing GPL V2</b></dt><dd>This is the appropriate option if you want to share the source code of your application with everyone you distribute it to, and you also want to give them the right to share who uses it. If you wish to use this software under Open Source Licensing, you must contribute all your source code to the open source community in accordance with the GPL Version 2 when your application is distributed. See <a href="http://www.gnu.org/copyleft/gpl.html">http://www.gnu.org/copyleft/gpl.html</a></dd></dl>
<dl class="user" compact><dt><b>Commercial Licensing</b></dt><dd>This is the appropriate option if you are creating proprietary applications and you are not prepared to distribute and share the source code of your application. Contact <a href="mailto:info@open.com.au">info@open.com.au</a> for details.</dd></dl>
<dl class="user" compact><dt><b>Revision History</b></dt><dd></dd></dl>
<dl class="version" compact><dt><b>Version:</b></dt><dd>1.0 Initial release<p>
1.1 Added speed() function to get the current speed. <p>
1.2 Added runSpeedToPosition() submitted by Gunnar Arndt. <p>
1.3 Added support for stepper drivers (ie with Step and Direction inputs) with _pins == 1</dd></dl>
<dl class="author" compact><dt><b>Author:</b></dt><dd>Mike McCauley (<a href="mailto:mikem@open.com.au">mikem@open.com.au</a>) </dd></dl>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 24 18:22:50 2010 for AccelStepper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>

BIN
doc/tab_b.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 B

BIN
doc/tab_l.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

BIN
doc/tab_r.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

102
doc/tabs.css Normal file
View file

@ -0,0 +1,102 @@
/* tabs styles, based on http://www.alistapart.com/articles/slidingdoors */
DIV.tabs
{
float : left;
width : 100%;
background : url("tab_b.gif") repeat-x bottom;
margin-bottom : 4px;
}
DIV.tabs UL
{
margin : 0px;
padding-left : 10px;
list-style : none;
}
DIV.tabs LI, DIV.tabs FORM
{
display : inline;
margin : 0px;
padding : 0px;
}
DIV.tabs FORM
{
float : right;
}
DIV.tabs A
{
float : left;
background : url("tab_r.gif") no-repeat right top;
border-bottom : 1px solid #84B0C7;
font-size : x-small;
font-weight : bold;
text-decoration : none;
}
DIV.tabs A:hover
{
background-position: 100% -150px;
}
DIV.tabs A:link, DIV.tabs A:visited,
DIV.tabs A:active, DIV.tabs A:hover
{
color: #1A419D;
}
DIV.tabs SPAN
{
float : left;
display : block;
background : url("tab_l.gif") no-repeat left top;
padding : 5px 9px;
white-space : nowrap;
}
DIV.tabs INPUT
{
float : right;
display : inline;
font-size : 1em;
}
DIV.tabs TD
{
font-size : x-small;
font-weight : bold;
text-decoration : none;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
DIV.tabs SPAN {float : none;}
/* End IE5-Mac hack */
DIV.tabs A:hover SPAN
{
background-position: 0% -150px;
}
DIV.tabs LI.current A
{
background-position: 100% -150px;
border-width : 0px;
}
DIV.tabs LI.current SPAN
{
background-position: 0% -150px;
padding-bottom : 6px;
}
DIV.navpath
{
background : none;
border : none;
border-bottom : 1px solid #84B0C7;
}

View file

@ -0,0 +1,28 @@
// Blocking.pde
// -*- mode: C++ -*-
//
// Shows how to use the blocking call runToNewPosition
// Which sets a new target position and then waits until the stepper has
// achieved it.
//
// Copyright (C) 2009 Mike McCauley
// $Id: HRFMessage.h,v 1.1 2009/08/15 05:32:58 mikem Exp mikem $
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to 4 pins on 2, 3, 4, 5
void setup()
{
stepper.setMaxSpeed(200.0);
stepper.setAcceleration(100.0);
}
void loop()
{
stepper.runToNewPosition(0);
stepper.runToNewPosition(500);
stepper.runToNewPosition(100);
stepper.runToNewPosition(120);
}

View file

@ -0,0 +1,22 @@
// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author Mike McCauley (mikem@open.com.au)
// Copyright (C) 2009 Mike McCauley
// $Id: HRFMessage.h,v 1.1 2009/08/15 05:32:58 mikem Exp mikem $
#include <AccelStepper.h>
AccelStepper stepper; // Defaults to 4 pins on 2, 3, 4, 5
void setup()
{
stepper.setSpeed(50);
}
void loop()
{
stepper.runSpeed();
}

View file

@ -0,0 +1,41 @@
// MultiStepper.pde
// -*- mode: C++ -*-
//
// Shows how to multiple simultaneous steppers
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Runs other steppers at the same time
//
// Copyright (C) 2009 Mike McCauley
// $Id: HRFMessage.h,v 1.1 2009/08/15 05:32:58 mikem Exp mikem $
#include <AccelStepper.h>
// Define some steppers and the pins the will use
AccelStepper stepper1; // Defaults to 4 pins on 2, 3, 4, 5
AccelStepper stepper2(4, 6, 7, 8, 9);
AccelStepper stepper3(2, 10, 11);
void setup()
{
stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(24);
stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(1000000);
stepper3.setMaxSpeed(300.0);
stepper3.setAcceleration(100.0);
stepper3.moveTo(1000000);
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
stepper1.run();
stepper2.run();
stepper3.run();
}

View file

@ -0,0 +1,31 @@
// Overshoot.pde
// -*- mode: C++ -*-
//
// Check overshoot handling
// which sets a new target position and then waits until the stepper has
// achieved it. This is used for testing the handling of overshoots
//
// Copyright (C) 2009 Mike McCauley
// $Id: HRFMessage.h,v 1.1 2009/08/15 05:32:58 mikem Exp mikem $
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to 4 pins on 2, 3, 4, 5
void setup()
{
}
void loop()
{
stepper.setMaxSpeed(200);
stepper.setAcceleration(50);
stepper.runToNewPosition(0);
stepper.moveTo(500);
while (stepper.currentPosition() != 300)
stepper.run();
// cause an overshoot as we whiz past 300
stepper.setCurrentPosition(600);
}

View file

@ -0,0 +1,30 @@
// Random.pde
// -*- mode: C++ -*-
//
// Make a single stepper perform random changes in speed, position and acceleration
//
// Copyright (C) 2009 Mike McCauley
// $Id: HRFMessage.h,v 1.1 2009/08/15 05:32:58 mikem Exp mikem $
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to 4 pins on 2, 3, 4, 5
void setup()
{
}
void loop()
{
if (stepper.distanceToGo() == 0)
{
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
delay(1000);
stepper.moveTo(rand() % 200);
stepper.setMaxSpeed((rand() % 200) + 1);
stepper.setAcceleration((rand() % 200) + 1);
}
stepper.run();
}

1294
project.cfg Normal file

File diff suppressed because it is too large Load diff