Hi Dewy,
Thanks for advice and your time.
I am still having trouble
when I include long someRandomPosition=rand() % 200;
Stepper just gets blocked.
With out that change motor always runs in one direction.
Pls take >look at the code, What I have done wrong?
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::FULL4WIRE, 8, 9, 10,11);
#define switchPinA 2
#define switchPinB 3
void setup()
{
pinMode(switchPinA,INPUT);
pinMode(switchPinB,INPUT);
digitalWrite(switchPinA,HIGH);
digitalWrite(switchPinB,HIGH);
}
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=rand() % 200;
stepper.setMaxSpeed((rand() % 200) + 1);
stepper.setAcceleration((rand() % 200) + 1);
if(digitalRead(switchPinA)==HIGH || digitalRead(switchPinB)==HIGH)
{
//someRandomPosition=someRandomPosition * -1; // just invert data
}
stepper.moveTo(-1);
}
stepper.run();
}