incrementing ?

Hi

My laptop decided to go to ground on me, taking most of my sweat and tears of recent weeks with it. (as all computers are inherently evil, they always die at the moment you think "i really should make a new backup next weekend")

But I digress before I made my point.

I was working on code to drive multiple stepping motors (which I'll have to write entirely again, most likely), managing to keep the code clean by putting most variables in arrays where position 0 = motor one, pos1 = motor two and so on...

But this still left me with mutiple instances of

(and I type it knowing full well this isn't even remotly realistic like this)

for (x=0; x<5, x++){
  if timearray(x) = time to step { // nevermind how the time is decided, that works
    if (x==0) motor1.step();  //number of steps comes from another array , that isnt a problem either
    if (x==1) motor2.step();
    ...
  }
}

The question hence = How can I "Array" (or something like it ? some form of enum ?) the terms 'motorX' so there don't need to be 5 instances of nearly the same IF ?

I do hope this makes sense :s If it doesn't I'm sure some of you will beat me into humility again :smiley:

You can create an array of Motor objects. Exactly how depends on the class (specifically, the constructor arguments). Post more of your code so we can help you.

well like I said, the code is gone, I need to write it again. which isn't bad, since i learn all the time ( I think) so i can make it "cleaner" in teh second writing

it is teh basic stepper library from the IDE

stepper Motor1 = stepper(x,y,z) where x = steps per 360°, y, z = output pins.

Now that you mention it, since the "stepper" library is blocking... maybe it's better to drive them one step each iteration of the loop (taking a reasonable delay to actually allow the motor to keep up) instead of using the library to step them X steps when it's time...

( but that's another thing entirely ... unless I can figure out how the digitalwrite High/low works when step() is called ...

I'm thinking out loud... sorry )

I'd have a look at

:slight_smile:

Yes. I have.

But I can't find the bit where it explains on how to getting multiple motors named in a way that allows me to use their different functions through a variable ?

stepper motor0 = stepper(80,5,6);
stepper motor1 = stepper(75,9,10);
and so on... let's say 56 motors so last is motor55


for x<55, x++
motor(x).setspeed( arrayspeed[x]  )
motor(x).step( arrayStepSize[x] )

for now it's more of a theorethical question.. while I brood on the price of laptops these days

Stepper motors[] =
{
stepper(80,5,6),
stepper(75,9,10),
};
will create an array of Stepper objects.

and so on... let's say 56 motors so last is motor55

Which Arduino are you using that has 112+ pins?

Probably the SupaDupa dual processor Arduino 5120 :stuck_out_tongue:

like I said... theorethical :wink:

It's THAT simple ? ok i feel like an idiot now (as well as look like one I guess),..

I would never have expected that to work when adding the ".setspeed" or ".step" part... to the point of not bothering to test it...

thanks!

I would never have expected that to work when adding the ".setspeed" or ".step" part... to the point of not bothering to test it...

You need to use the correct notation, to use the methods of an object in an array. To move the first motor:

motor[0].step(someNumberOfSteps);

PaulS:
Stepper motors[] =
{
stepper(80,5,6),
stepper(75,9,10),
};
will create an array of Stepper objects.

Shouldn't those two "stepper"s be capitalized? i.e., Stepper(80,5,6), Stepper(75,9,10)

Shouldn't those two "stepper"s be capitalized? i.e., Stepper(80,5,6), Stepper(75,9,10)

Yes.

OK, thanks for clarification. It took me forever to find this solution, so to help others find it, I'll post:

initialize array of Stepper objects
initialize array of Stepper instances
make array of Stepper objects
make array of Stepper instances

as search phrases that will hopefully help others find this!

Stepper motors[] =
{
Stepper(80,5,6),
Stepper(75,9,10)
};