#include <Arduino.h>
#include <ShiftRegister74HC595.h>
// https://github.com/Simsso/ShiftRegister74HC595

const int dataPin = 5;   /* DS */
const int clockPin = 19; /* SHCP */
const int latchPin = 18; /* STCP */

ShiftRegister74HC595<2> sr(dataPin, clockPin, latchPin);

// 电机正转
void forward(unsigned long STEPS_PER_REV)
{
  unsigned int delayTime = 2000;

  // 设置电机顺时针旋转
  // digitalWrite(dirPin, LOW);
  sr.set(6, LOW);
  sr.set(4, LOW);
  sr.set(2, LOW);
  sr.set(0, LOW);

  sr.set(14, LOW);
  sr.set(12, LOW);
  sr.set(10, LOW);
  sr.set(8, LOW);

  // 电机慢速旋转
  for (int x = 0; x < STEPS_PER_REV; x++)
  {
    // digitalWrite(stepPin, HIGH);
    sr.set(7, HIGH);
    sr.set(5, HIGH);
    sr.set(3, HIGH);
    sr.set(1, HIGH);

    sr.set(15, HIGH);
    sr.set(13, HIGH);
    sr.set(11, HIGH);
    sr.set(9, HIGH);
    delayMicroseconds(delayTime);
    // digitalWrite(stepPin, LOW);
    sr.set(7, LOW);
    sr.set(5, LOW);
    sr.set(3, LOW);
    sr.set(1, LOW);

    sr.set(15, LOW);
    sr.set(13, LOW);
    sr.set(11, LOW);
    sr.set(9, LOW);
    delayMicroseconds(delayTime);
  }
}

void setup()
{
}

void loop()
{
  forward(200);
  delay(1000);
}
74HC595
A4988
A4988
A4988
A4988
A4988
A4988
74HC595
A4988
A4988