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
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 ...
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