I've been manipulating and rewriting both programs to no avail. In the first program i used i just don't understand why the serial read is "232230", but after atoi it's some oddball negative number.
I tried using this program
#include <stdlib.h>
char X_buffer[3];
char Y_buffer[3];
int received;
int i=0;
int X_pos=0;
int Y_pos=0;
void setup()
{
Serial.begin(57600);
received = 0;
X_buffer[received] = '\0';
Y_buffer[received] = '\0';
Serial.println("setup");
}
void loop()
{
if (Serial.available())
{
// Get x cord
for(i=0; i<3; i++)
{
X_buffer[i] = Serial.read();
}
// Get y cord
for(i=0; i<3; i++)
{
Y_buffer[i] = Serial.read();
}
X_pos = atoi(X_buffer);
Y_pos = atoi(Y_buffer);
Serial.print("x:");
Serial.print(X_pos);
Serial.print("y:");
Serial.print(Y_pos);
Serial.println();
}
}
with output
setup
x:2y:0
x:32230y:30
x:2y:0
x:-32306y:30
x:2y:0
x:32230y:30
x:2y:0
x:32230y:30
correct output should have been "232230"
i'm sending the data by:
Serial.print((int)chuck.readJoyX()*-1+100); //make is positive and always 3 digits long
// Serial.print(",jy ");
Serial.print((int)chuck.readJoyY()*-1+100); //make is positive and always 3 digits long
i've tried taking out the (int) makes no difference. I'm sending it as integer ascii?
here's the original program output
setup
*232230*-29914*
*233230*-28914*
*232230*-29914*
*232230*-29914*
it's getting the right 232230... after atoi it's unusable