Stepper - Class Reference
#include "TeensyStep.h"

Objects of the Stepper class store the physical properties of a stepper motor and the pins it is connected to. The target position of a a stepper object is used by the StepControl class to actually move the motor. Stepper objects also maintain a step counter which reflects the current motor position. Writing to the step counter is possible to set the counter to zero (or some offset) at the home position.

Construction

Stepper(unsigned stpPin, unsigned dirPin)

Constructs a stepper object with the given pin numbers for STEP and DIR signals

Setup Functions

Stepper& setMaxSpeed(int32_t speed)

Sets the maximum speed of the motor in steps/s.

Stepper& setAcceleration(uint32_t accel)

Sets the maximum acceleration of the motor in steps/s².

Stepper& setStepPinPolarity(int polarity)

Sets the polarity of the generated step pulses. setStepPinPolarity(HIGH) generates active high pulses. setStepPinPolarity(LOW) generates active low pulses.

Stepper& setInverseRotation(int polarity)

Use this function to change the polarity of the generated direction signal. setInverseRotation(true) sets the DIR pin to LOW if the motor runs in ‘upward direction’

 // you can use the standard interface for setup
 motor_1.setAcceleration(5000);
 motor_1.setMaxSpeed(10000);       

 // ...or a fluent interface
 motor_2
  .setAcceleration(20000)
  .setMaxSpeed(15000)
  .setInverseRotation(true)
  .setStepPinPolarity(LOW);

Motor Positioning

void setTargetAbs(int32_t position)

Sets the target position in steps. To actually move the motor, use one of the controller objects

void setTargetRel(int32_t delta)

Sets the target position relative to the current position. To actually move the motor, use one of the controller objects

void setPosition(int32_t counterValue)

Sets the internal step counter to the parameter counterValue. This function is NOT setting a new target position. Typically, you only use this function after homing to set the counter to zero or some offset value.

int32_t getPosition()

Returns the current position of the stepper.