Hi All,
Firstly Thanks for looking and Many Thanks if you can help solve my issue.
Persistance is the key - but i''m running out of persistance >:(
Basically i am trying to write generic code for as much of my project as possible and for a large part i have suceeded... until now
I have 3 functions to control the output of a single servo motor rotation to a specified position, namely Danger, Clear and Clear with Bounce. I call these functions in a FSM when needed and everything works as it should. I have duplicated these functions for a second servo motor (renaming the relevant variables and function name) and again it all works as it should.
Thats 2 servo motors but the project requires 20 so thats a lot of coding and renaming so I am at the Generic Code Crossroads.
I'm new at coding and this generic malarky is frying my brain so Is there a way of making this generic within a function ?
void servoToDanger() {
downMainStarterServo.attach (downMainStarterServoMotorPin);
// Signal From Clear Position To Danger Position
for (signalPosition = (downMainStarterClearPosition); signalPosition >= (downMainStarterDangerPosition); signalPosition = (signalPosition - (downMainStarterDangerDegreeSteps))) // for (goes from position, goes to position, increment position each time through for loop)
{
downMainStarterServo.write(signalPosition);
delay(downMainStaterDangerTravelSpeed);
}
downMainStarterServo.detach ();
}
and my variables
int downMainStarterDangerPosition = 70; // Sets the Danger Position (This number can be altered to fine tune the arm position to horizontal position).
int downMainStarterDangerDegreeSteps = 1; // Sets the Degree of Rotation for each step through the code [1. Must be whole number; 2.The higher the number the quicker it rotates through the code)
int downMainStaterDangerTravelSpeed = 25; // Sets a delay between each step through the code [1. Has to be a whole number; 2. The higher the number the slower it rotates]
int downMainStarterClearPosition = 100; // Sets the Clear Position (This number can be altered to fine tune the arm position to dropped position).
int downMainStarterClearDegreeSteps = 2; // Sets the Degree of Rotation for each step through the code [1. Must be whole number; 2.The higher the number the quicker it rotates through the code)
int downMainStarterClearTravelSpeed = 15; // Sets a delay between each step through the code [1. Has to be a whole number; 2. The higher the number the slower it rotates]
bool downMainStarterBounceOn = false; // Set to "false" there will be no Signal Bounce; Set to "true" there will be Signal Bounce
int downMainStarterBouncePosition = 76; // Sets theBounce Position (This number can be altered to fine tune the arm position that the arm bounces up too).
int downMainStarterBounceDegreeSteps = 1; // Sets the Degree of Rotation for each step through the code [1. Must be whole number; 2.The higher the number the quicker it rotates through the code)
int downMainStarterBounceTravelSpeed = 15; // Sets a delay between each step through the code [1. Has to be a whole number; 2. The higher the number the slower it rotates]
And more importantly how to make the attach part of the servo generic
downMainStarterServo.attach (downMainStarterServoMotorPin);
So why am i attaching and detaching the servo?... only to reduce chatter, they are cheap servos, whether or not thats a good idea i'm sure i'll find out. :
This is one of the 3 functions BUT im positive the answer to them all is the same as the answer to this piece of code as they are all similar.
Thanks in advance