// https://wokwi.com/projects/388661915235241985

// Note that this Wokiwi Simulation has several tabs --
// dual_stepper_Scope.ino -- two steppers based on Accelstepper
// FastAccelRamping.ino.txt -- fastaccelstepper
// MinimalCode.ino.txt -- hand-rolled stepper code
// noCode.txt -- just using wiring
// rename a single tab to .ino to use that code

// DualMotorShield.pde
// from https://github.com/waspinator/AccelStepper/blob/master/examples/DualMotorShield/DualMotorShield.pde
// -*- mode: C++ -*-
//
// Shows how to run 2 simultaneous steppers

// Runs both steppers forwards and backwards, accelerating and decelerating
// at the limits.
//
// Copyright (C) 2014 Mike McCauley
// $Id:  $

#include <AccelStepper.h>

// The X Stepper pins
#define STEPPER1_DIR_PIN 7
#define STEPPER1_STEP_PIN 10
// The Y stepper pins
#define STEPPER2_DIR_PIN 8
#define STEPPER2_STEP_PIN 9

// Define some steppers and the pins the will use
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);

void setup()
{
  stepper1.setMaxSpeed(200.0);
  stepper1.setAcceleration(200.0);
  stepper1.moveTo(100);

  stepper2.setMaxSpeed(100.0);
  stepper2.setAcceleration(100.0);
  stepper2.moveTo(100);
  Serial.begin(115200);
}

void loop()
{
  // Change direction at the limits
  if (stepper1.distanceToGo() == 0)
    stepper1.moveTo(-stepper1.currentPosition());
  if (stepper2.distanceToGo() == 0)
    stepper2.moveTo(-stepper2.currentPosition());
  stepper1.run();
  stepper2.run();
  checkAccel();
}

void checkAccel(void) {
  static int lastPot = -1;
  static uint32_t lastCheckMs = 0;
  if (millis() - lastCheckMs > 100) {
    lastCheckMs = millis();
    int potVal = analogRead(A0);
    if (lastPot != potVal) {
      Serial.print("p");
      lastPot = potVal;
      stepper1.setAcceleration(map(potVal, 0, 1023, 1, 400));
      stepper2.setAcceleration(map(potVal, 0, 1023, 1, 200));
    }
  }
}
A4988
A4988
Loading chip...chip-scope