Stuck on stepper code

Hi there,

I have bought a stepper linear actuator from ebay:

http://www.ebay.co.uk/itm/180772065982?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

I have wired it up like a bipolar stepper motor with hbridge on this Arduino example page see link:

I am now stuck on the code - would anyone be able to help me? I only seem to be able to find code for turning one direction or another with a sensors reading or code that is just to complicated for me to understand it. I am also very new to coding so have pretty much no knowledge when it comes to using the arduino library as reference.

I would like to make the motor turn in one direction for an adjustable period of time and for an adjustable speed and then turn the other way for an adjustable period of time and speed. Please could someone help me with the code needed for this?

Many thanks and looking forward to your responses.

Since you don't say, I'll assume your values are 'adjustable' with more knobs.

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

const unsigned int minMilliseconds = 100;  // Minimum motion time 1/10th of a second
const unsigned int maxMilliseconds = 10000;  // Maximum motion time 10 seconds
const unsigned int minSpeed = 1;  // 1 RPM
const unsigned int maxSpeed = 30; // 30 RPM

void setup()
{
  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(30);
}

void loop()
{
  unsigned int forwardTime   = map(analogRead(0), 0, 1023, minMilliseconds, maxMilliseconds));
  unsigned int backwardTime = map(analogRead(1), 0, 1023, minMilliseconds, maxMilliseconds));
  int speed = map(analogRead(2), 0, 1023, minSpeed, maxSpeed));

  stepper.setSpeed(speed); // 1 to 30 RPM
  unsigned long millisecondsPerRevolution = 60000UL / speed;
  unsigned long millisecondsPerStep = millisecondsPerRevolution/STEPS ;

  // Calculate how many steps based on time and speed
  int forwardSteps = forwardTime / millisecondsPerStep;
  stepper.step(forwardSteps);

  int backwardSteps = backwardTime / millisecondsPerStep;
  stepper.step(-backwardSteps);
}
[code]

[/code]

Hi there,

Thanks so much for getting back to me so quickly. I have run the code through the Arduino software but it came up with the following error for the following line of code:

error:

sketch_aug04a.ino: In function 'void loop()':
sketch_aug04a:24: error: expected ',' or ';' before ')' token
sketch_aug04a:25: error: expected ',' or ';' before ')' token
sketch_aug04a:26: error: expected ',' or ';' before ')' token

this code highlighted:

unsigned int forwardTime = map(analogRead(0), 0, 1023, minMilliseconds, maxMilliseconds));

Do you know how to rectify this error? as I am unsure?

hope to hear from you again soon.

Thanks so far.

Aphra:
sketch_aug04a.ino: In function 'void loop()':
sketch_aug04a:24: error: expected ',' or ';' before ')' token
sketch_aug04a:25: error: expected ',' or ';' before ')' token
sketch_aug04a:26: error: expected ',' or ';' before ')' token

this code highlighted:
unsigned int forwardTime = map(analogRead(0), 0, 1023, minMilliseconds, maxMilliseconds));

Yes, I know how to rectify the error. You should be able to figure it out from the error message and a careful reading of the failing statement. Consider it part of the learning process.