// https://wokwi.com/projects/413856149971298305
// with STEP/DIR driver

// https://wokwi.com/projects/410057894146947073
// Code from https://github.com/waspinator/AccelStepper/blob/master/examples/Bounce/Bounce.pde
// Other example simulations https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754
// See also: https://wokwi.com/projects/382572037362027521 -- Bounce Modified to report acceleration status
// You should not drive a stepper direcly from the controller
// Use a modern H-bridge driver like a TB6612FNG, or an old, 
// inefficient L298N, or a modern STEP+DIR driver.

// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.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
AccelStepper stepper(AccelStepper::DRIVER,2,3); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
//AccelStepper stepper(3,2,3); // Craziness due to the 3-phase misconfiguration and default use of pin 4 


void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}
Loading chip...chip-scope
A4988