well, good morning campers-
i built a little pen plotter and am working on the program to control it. i have no formal training and this is to help build my skills in this area. the idea is to feed in a string containing all the move commands for a given sequence. a square, a circle, a letter. that type of thing. each command starts with a letter, xdirection, xstep count, on of these guys "/" and then the ydirection and step count, or just a letter in the case of extend and retract as those don't change.
so far i worked out how to strip an individual command from the incoming string. that uses the asterisk to mark this as pointer, i believe. that works fine. then i can use the index of the array for the current command to cycle through it to compare each character. that all works too. i can use the incomingstep[i] to evaluate the character, i can print it to the screen, i can copy it to an int type and print that and it'll show "49" which is correct. we are looking at the number one in the character array. perfect. exactly what i need.
it will NOT strcpy or strcat.
not even after copying to an int and then copying that int to a different character array entirely and trying to strcat that new array.
i know this stuff is considered rough learning, but i want to bounce my head off this desk after three days of doing this..
everything i try shows the correct values and i can do anything i wish with them aside from being able to actually use them.
please help if you can.
you can see what i am trying to do near the bottom.
right about where the names start to lose meaning..
char *currentstring[] = {"R","Q+200/-200","E","M+100/-100","moist","R","Q+200/-200","E","M+100/-100"};
int currentstringindex = 0;
char incomingstep[100];
int currentstringcomplete = 0;
char xgoal[100] = {'\0'};
char ygoal[100] = {'\0'};
void setup() {
Serial.begin(9600);
while (!Serial) {
}
delay(3000);
Serial.println("funckles da clone");
delay(1000);
}
void loop() {
if (currentstringcomplete == 0) {
currentstringindex = parsecommand(currentstring, currentstringindex);
delay(500);
}
}
void retract() {
Serial.println("we have retracted");
}
void extend() {
Serial.println("we have extended");
}
int parsecommand(char *incomingcommand[], int incomingcommandindex) {
if (incomingcommand[incomingcommandindex] == '\0') {
incomingcommandindex = 0;
currentstringcomplete = 1;
Serial.println("that's it, cap'm");
return incomingcommandindex;
}
else if (incomingcommand[incomingcommandindex] != '\0') {
strcpy(incomingstep, incomingcommand[incomingcommandindex]);
for (int i = 0; i < strlen(incomingstep); i++) {
if (incomingstep[i] == 'R') {
retract();
incomingcommandindex = incomingcommandindex + 1;
return incomingcommandindex;
}
else if (incomingstep[i] == 'E') {
extend();
incomingcommandindex = incomingcommandindex + 1;
return incomingcommandindex;
}
else if (incomingstep[i] == 'Q') {
Serial.println(incomingcommand[incomingcommandindex]);
incomingcommandindex = incomingcommandindex + 1;
return incomingcommandindex;
}
else if (incomingstep[i] == 'M') {
Serial.print(incomingcommand[incomingcommandindex]);
i++;
if (incomingstep[i] == '+') {
Serial.println(" <---positive");
}
else if (incomingstep[i] == '-') {
Serial.println(" <---negative");
}
i++;
if (isDigit(incomingstep[i])) {
Serial.println(xgoal);
Serial.println(incomingstep[i]);
int goathole = incomingstep[i];
char thisfatthing = goathole;
strcat(xgoal, thisfatthing);
Serial.println(thisfatthing);
Serial.println(xgoal);
}
incomingcommandindex = incomingcommandindex + 1;
return incomingcommandindex;
}
else if (incomingcommand[incomingcommandindex] != '\0') {
Serial.print("unknown---> ");
Serial.println(incomingcommand[incomingcommandindex]);
incomingcommandindex = incomingcommandindex + 1;
return incomingcommandindex;
}
delay(500);
}
}
}