stepper-motor
Arduino library to accurately control a stepper motor
Public Member Functions | List of all members
StepperMotor::Driver Class Reference

Driver for an 8-step stepper motor More...

#include <stepper_motor.h>

Public Member Functions

 Driver (std::initializer_list< uint8_t > pins)
 Create a new driver instance using the given pins. More...
 
void turn (int16_t degree)
 Relative turn. More...
 
void turnTo (uint16_t target_angle)
 Absolute turn. More...
 
void setStepsPerRotation (uint16_t steps)
 Set the steps needed for one complete rotation. More...
 
void setWaiter (void(*waiter)(unsigned int))
 Set a custom waiter. More...
 

Detailed Description

Driver for an 8-step stepper motor

Example

using Stepper = StepperMotor::Driver;
Stepper motor({2, 3, 4, 5});
void loop() {
motor.turn(-90);
delay(1000);
motor.turnTo(0);
delay(3000);
}

Definition at line 24 of file stepper_motor.h.

Constructor & Destructor Documentation

StepperMotor::Driver::Driver ( std::initializer_list< uint8_t >  pins)

Create a new driver instance using the given pins.

Parameters
pinsExactly 4 pins.

Definition at line 17 of file stepper_motor.cpp.

Member Function Documentation

void StepperMotor::Driver::setStepsPerRotation ( uint16_t  steps)

Set the steps needed for one complete rotation.

This defaults to 510, which is a common value for stepper motors found in arduino starter kits.

Parameters
stepsThe steps per rotation.

Definition at line 63 of file stepper_motor.cpp.

void StepperMotor::Driver::setWaiter ( void(*)(unsigned int)  waiter)

Set a custom waiter.

Use this if you want to run some code while the motor is turning. Your custom function must wait at least the given amount of microseconds before returning. The default is delayMicroseconds.

Parameters
waiterThe new waiter function.

Definition at line 67 of file stepper_motor.cpp.

void StepperMotor::Driver::turn ( int16_t  degree)

Relative turn.

This turns the motor the given number of degrees in the direction given by the sign (positive = turn right). Supports turns larger than one complete turn (360°).

Parameters
degreeThe number of degree to turn the motor.

Definition at line 26 of file stepper_motor.cpp.

void StepperMotor::Driver::turnTo ( uint16_t  target_angle)

Absolute turn.

Turn the motor to the given angle. Always uses the shortest path to the requested angle and even works after relative turns.

Parameters
target_angleThe target angle in degree.

Definition at line 46 of file stepper_motor.cpp.


The documentation for this class was generated from the following files: