// https://wokwi.com/projects/410058296261374977
// Code from https://www.airspayce.com/mikem/arduino/AccelStepper/ProportionalControl_8pde-example.html
// Other example simulations https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754
// See also  https://wokwi.com/projects/408621270297541633 with acceleration
//
//  Note that the A4988's STEP/DIR pins are connected to two 
//  separate phases of a 4-wire quadrature signal from the code.
//  This works but is 4x slower.  It is more effective to use the 
//  AccelStepper::DRIVER initialization parameter like:
//     AccelStepper stepper(AccelStepper::DRIVER,4,3);
//  This simulation shares both wirings so the code
//  distributed with AccelStepper works as-is
//
// Also, one should always use driver between the Uno and 
// the stepper. Something like an L298 or the much more 
// efficient TB6612FNC.
//
// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton, 
// depending on the value of the pot.
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0

void setup()
{  
  stepper.setMaxSpeed(1000);
}

void loop()
{
  // Read new position
  int analog_in = analogRead(ANALOG_IN);
  stepper.moveTo(analog_in);
  stepper.setSpeed(100);
  stepper.runSpeedToPosition();
}
Loading chip...chip-scope
Wokwi-stepper-motor AccelStepper.h demo.
Position 1023 CW CCW 0
A4988