You are on page 1of 1

/// @file

/// Example of using 74HC595 shift registers to drive 8 stepper motors.


#include <SerialStepper.h>
#include <ArduinoStepper.h>
//#include <SPI.h>

/// Define the number of steppers


constexpr auto nsteppers = 3;

/// Define the pin to use as latch pin


constexpr int latch_pin = 4; // for Attiny85

/// Define the Stepper motors.


Stepper serial_steppers[3];

/// Define the StepperControl.


ArduinoStepperControl stepper_ctl[] = {
ArduinoStepperControl {0,1,2,3},
ArduinoStepperControl {6,7,8,9},
ArduinoStepperControl {14,15,16,17}};

/// This is called once at start-up.


void setup() {

/// Initialize libraries.


// SPI.begin();

/// Initialize the stepper motor controller.


stepper_ctl.begin();
for (auto& stepper : steppers) {
stepper_ctl.addStepper(stepper);
}

/// Set different speed for each Stepper.


constexpr float max_speed = 15.0f;
for (int i = 0; i < nsteppers; ++i) {
steppers[i].speed(max_speed - 1.0f * i);
}
}

/// This is called repeatedly.


void loop() {

/// Update the clock.


loopClock::tick();

/// Give commands to the steppers.


for (auto& s : steppers) {
if (!s.running()) {
s.direction(!s.direction());
s.turn(15);
}
}

/// Move the steppers if due time.


for (auto& ctl : stepper_ctl) {
ctl.run();
}

You might also like