This simulation doesn't do a deadband, but it does proportional +/- speed control or proportional position control, built from an AccelStepper example:
// https://wokwi.com/projects/428502497518500865
//
// modified to use a driver. Based on:
// 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
//
// Driver example
//
// 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
//
//
// ProportionalControlV2.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move with acceleration to each newly set posiiton,
// depending on the value of the pot, or in Speed mode, move CW or CCW at
// variable speed,
//
// 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(AccelStepper::DRIVER, 4, 3);
// 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
#define MODE_PIN A1
void setup()
{
stepper.setMaxSpeed(1000); // steps/sec
stepper.setAcceleration(100); // steps/sec/sec
pinMode(MODE_PIN, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(MODE_PIN) == HIGH) { // Position mode
// Read new position
int analog_in = analogRead(ANALOG_IN);
//stepper.setSpeed(100);
stepper.moveTo(analog_in);
stepper.run();
} else {
int analog_in = analogRead(ANALOG_IN);
//stepper.moveTo(analog_in);
stepper.setSpeed(map(analog_in, 0, 1023, -100, 100));
stepper.runSpeed();
}
}
Other Wokwi simulation examples in this thread:
