Hi All,
I'm working on a project where I have to send string commands to a stepper motor controller. These commands look typically like "10030XYG" or "-1500X45000YG" and tell the control board how many steps to move the X or Y motors. I have a separate program that can take commands that I type in, load these command strings into an array, and send them out to the control board as needed. But, what I really want to to is randomly generate the X and Y positions, convert those to strings, append the X/Y/G charachters, and then load them into the array.
I'm trying to get my head around getting everything in a string format that will load into the "char* stepArray[]" string array. So, I made another test program shown here in order to get this portion to work. I'm using String objects for now, but they don't seem to agree with the char* stepArray[]. I get a "String_Tests:51: error: cannot convert 'String' to 'char*' in initialization" error line. I understand string objects are not recommended due to memory issues. But, so far, trying to get one command string out of a character array is proving difficult. I've also fooled around with using "ltoa" to convert the random long numbers into strings, but then I have to append the letters and so forth.
I think that if I can get my stepArray[] array to load up, I should have this issue licked. Thanks for any help and recommendations,
--> K
/*
Test program to convert random integers into strings commands to send to Stepper Control Board.
*/
//******************Constants***********
//******************Variables***********
String stepCommand = "";
//****************Function Prototypes******
//***************Setup******************************
void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));
}
//*************Main Program Loop************************
void loop() {
long randNumber_X1 = random(-10000, 10001);
long randNumber_Y1 = random(-10000, 10001);
long randNumber_X2 = random(-10000, 10001);
long randNumber_Y2 = random(-10000, 10001);
Serial.print(randNumber_X1);
Serial.print(" ");
Serial.println(randNumber_Y1);
Serial.print(randNumber_X2);
Serial.print(" ");
Serial.println(randNumber_Y2);
String firstPosition = stepCommand + randNumber_X1 + "X" + randNumber_Y1 + "Y" + "G";
String secondPosition = stepCommand + randNumber_X2 + "X" + randNumber_Y2 + "Y" + "G";
String homePosition = "0XYG";
Serial.println(firstPosition); //This prints to Serial Monitor as expected
Serial.println(secondPosition); //This prints to Serial Monitor as expected
Serial.println(homePosition); //This prints to Serial Monitor as expected
char* stepArray[] = { //Load up CNC Patterns into string array. HOW TO LOAD STRINGS???
firstPosition,
secondPosition,
homePosition
};
}
//*********************FUNCTIONS***************************
//**************************************************************************