Where first set is X and second Y
I've been trying to fit 's between and so on,
problem is how to get those number to invidual char's inputx[] and inputy[].
I have managed to control one axel x or y just fine, but havent figuret out how to separate those on serial.read...
This is code for reading just one serial input what i have been using
Using Serial.available will return 1 if there is only one character available, but then you read four.
The other three will probably be -1.
You need to check before you read each character, or test "available" to be at least four.
"atoi" works on C strings, so you need to terminate your character array with a zero.
Thanks for replies, but little bit foorum searching paid, found solution.
if(Serial.available()>0)
{
ch = Serial.read(); // Read another character
i=0;
while(ch != 13) // 13 is ascii value of carriage return
{
inputx[i] = ch; // add the ASCII character to the string;
i++;
inputx[i] = '\0';
ch = Serial.read(); // Read another character
}
i=0;
ch = Serial.read(); // Read a character
while(ch != 13) // 13 is ascii value of carriage return
{
inputy[i] = ch; // add the ASCII character to the string;
i++;
inputy[i] = '\0';
ch = Serial.read(); // Read another character
}
etaisyysx=atoi(inputx);
etaisyysy=atoi(inputy);
.
.
.
.