#include <AccelStepper.h>
const int ptSpeed = 2;
const int ptPos = 15;
const int w1 = 19;
const int w2 = 18;
const int w3 = 5;
const int w4 = 17;
int position = 0;
int speed = 0;
AccelStepper stp(AccelStepper::FULL4WIRE, w1, w2, w3, w4);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(ptSpeed, INPUT);
pinMode(ptPos, INPUT);
stp.setMaxSpeed(20000);
stp.setAcceleration(5000);
while(!Serial);
}
void loop() {
//Reads and converts the speed and position
int speed = map(analogRead(ptSpeed), 0, 4095, 0, 10000);
int position = map(analogRead(ptPos), 0, 4095, 0, 2000);
Serial.println("Speed = " + String(speed) + " position = " + String(position));
stp.moveTo(position);
stp.setAcceleration(speed);
stp.run();
delay(10);
//delayMicroseconds(speed);
//delay(speed); // this speeds up the simulation
}
Speed
Position