controller state and values

Hello,

i want to send the state of a two axis joystick and two buttons from a controller over Serial using two XBee modules. JoystickX, JoystickY, button1 and button2. I get values for the joystick that range from two to three digit integers (say values of about 70 - 200) and the buttons are single digit integers, 0 and 1, showing the button on and off. I thought I'd convert the integers to HEX, send them over the serial connection, then convert back to int on the other side. the position of the values relative to a final println determine what the value represents. does it make sense to do it this way? Any suggestion?

thanks

Any suggestion?

Just makes sure you’ve got some easily recognisable delimeter that can’t be mistaken for data, between frames of data.

The use of delimiters is important. I’d suggest two, though. One to mark the start of data, the other to mark the end of the data. Separate the values with a delimiter, too.

For example, send “<170, 240,0,1>”.

The receiver then knows what constitutes a valid frame. If it, for some reason, sees “0,1>\n<180,259,1,0>\n<129,” as available to read, it would know that the first few bytes do not constitute a complete frame, so it would not try to do anything with “0,1>\n”.