Ok for that, let's take a look at the
AccelStepper command reference:
First, lets fix the brakes:
From:
Quickstop.pde.
We'll need to add the use of:
stop() "Sets a new target position that causes the stepper to stop as quickly as possible..."
runToPosition() "Moves the motor at the currently selected constant speed (forward or reverse) to the target position..."
Now lets rev up the minimum speed:
setMaxSpeed() "Sets the maximum permitted speed."
void loop()
{
if (stepper.distanceToGo() == 0)
{
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
delay(1000);
long someRandomPosition=random(lowestRandomNum, highestRandomNum);
stepper.setMaxSpeed(random(
10, highestRandomNum) + 1);
stepper.setAcceleration(random(1, highestRandomNum) + 1);
if(digitalRead(switchPinA)==HIGH || digitalRead(switchPinB)==HIGH)
{
someRandomPosition=someRandomPosition * -1; // just invert data
stepper.stop(); // Stop as fast as possible: sets new target
stepper.runToPosition();
}
stepper.moveTo(someRandomPosition);
}
stepper.run();
}
Ok, that's my limit of two freebies per customer. Its your turn to hack at it.
