Hello all,
I am not sure if my approach to this problem in the correct. My project will involve two servo motors which are going to get their positions from an array. Currently my program doesn't include any servo motors attached. I am still trying to work out how to remove the leading zero's from the array. I need to keep in mind that if the array only contains 0's that the servo's are to be at the orgin (next to home)
/*
- direction = 11
+ direction = 22
Example of data format:
A) X+000000Y-000000 Orgin
B) X+003000Y-011500 Tool path
*/
void setup()
{
int R = 0;
int C = 0;
int const X = 88; // Servo X
int const Y = 89; // Servo Y
int valueX = 0; // Path X
int valueY = 0; // Path Y
int directionX = 0; // + or -
int directionY = 0; // + or -
/*
P = not needed
A = might need
P P A P A
{X, 22, 0, 0, 3, 0, 0, 0, Y, 11, 0, 1, 1, 5, 0, 0}
*/
int Co_Ords[1] [16] // Current XY values and clockwise/anti-clockwise direction
{
{X, 22, 0, 0, 3, 0, 0, 0, Y, 11, 0, 1, 1, 5, 0, 0}
};
Serial.begin(9600);
for (R = 0; R < 1; R++)
{
for (C = 0; C < 16; C++)
{
Serial.print(Co_Ords [R] [C]);
}
}
}
void loop() {
}
What on earth do you mean, "remove the leading zero's from the array"? There is no explanation anywhere in your post or your code about how this program works (enough for anyone else but you to read, anyway).
int const X = 88; // Servo X
int const Y = 89; // Servo Y
In the array I can't place a value of X or Y. I replaced X,Y with decimal values X = 88 and Y = 89. I replaced (-) with a value of 11 and (+) with a value 22.
/*
P = not needed
A = might need
P P A P A
{X, 22, 0, 0, 3, 0, 0, 0, Y, 11, 0, 1, 1, 5, 0, 0}
*/
What precisely makes them "leading"? Also what determines the position of the numbers in the array? What do you want to do with the spaces that would be left by removing zeros? Shift all the values left? Fill with another character?
Why do you have the strange encodings for "+" and "-"?
Think about how strange this problem must look to someone who has no familiarity with what you are trying to do! Then explain better.
The way the code is (X+) is not a value, nor is (Y-).
That seems to be completely missing the point. Your initial statement was:
My project will involve two servo motors which are going to get their positions from an array
That IMPLIES that the array contains TEXT.
char array[] = "X+003000Y-011500";
In this case, the question of how to get rid of leading 0s is both relevant and irrelevant.
Once you determine that the X value's string is "+003000", then atoi() will convert the string to a int value, 3000. Once you determine that the Y value's string is "-011500", atoi() will convert the string to an int value, -11500.
If you have the data in some other format (besides text), you need to explain just what form at it is in, and quit trying to force it to be in some other format.
int const X = 88; // Servo X
int const Y = 89; // Servo Y
I made X, Y a value (88, 89). I also made + , - a value (22, 11).
X, Y and -, + will always be in the array. The direction of each axis is decided by the next value 22 or, 11 in the array. The value will make the servo move anti-clockwise or, clockwise.
I made X, Y a value (88, 89). I also made + , - a value (22, 11).
X, Y and -, + will always be in the array. The direction of each axis is decided by the next value 22 or, 11 in the array. The value will make the servo move anti-clockwise or, clockwise.
maybe describe what you are actually trying to do rather than your approach to the solution.