Hi!
When setting up libraries with different settings, is it possible to put the name of the instance in a for loop and loop through it?
I'm probably not explaining myself correct, but let me show with code:
stepper1.setMaxSpeed(maxSpeed);
stepper1.setAcceleration(acc);
"stepper1" is what I want to put in a for loop, so I don't have to repeat so much code when changing settings for the steppers.
I also want you to take a look at a function I wrote for controlling 8 relays, what you would have done different etc.
boolean relays[8];
boolean relay(int relay, boolean highLow){
//////////////////////////////////////////////////////////////////////////////
if(highLow){ // if highLow == HIGH
mcp.digitalWrite(relay, HIGH); // Write HIGH to relayPin
delay(1); // Wait just a little tad
byte DR = mcp.digitalRead(15-relay); // Read output of pin
if(DR){ // If HIGH
relays[relay] = true; // Set relay as ON in array
return 1; // Return 1, relay is ON
}
else if(!DR){ // else if pin is still LOW // This is IF something goes wrong with the first write
mcp.digitalWrite(relay, HIGH); // Do a new write with HIGH
delay(1); // Wait a little before reading
if(mcp.digitalRead(15-relay)){ // If actually HIGH this time
relays[relay] = true; // Then set relay as ON in array
return 1; // Return 1, relay is ON
}
}
}//////////////////////////////////////////////////////////////////////////////
else if(!highLow){ // if highLow == LOW
mcp.digitalWrite(relay, LOW); // Write relayPin, LOW
delay(1); // Wait
byte DR = mcp.digitalRead(15-relay); // Read output pin
if(!DR){ // If pin is LOW
relays[relay] = false; // Set relay as OFF
return 0; // Return 0, relay is OFF
}
else if(DR){ // else if output is still HIGH // This is IF something goes wrong with the first write
mcp.digitalWrite(relay, LOW); // Do a new write to relay pin
delay(1); // Wait
if(!mcp.digitalRead(15-relay)){ // Do a new read, and if LOW
relays[relay] = false; // Set relay as OFF
return 0; // Return 0, relay is OFF
}
}
}
}
Thanks!