Virtual joystick coordinate swap problem (Arduino RC Car)

Hello. I've created a joystick using image sprites and canvas on app inventor. The purpose of this joystick is to control the rc car. X axis data controls the servo motor and Y axis data controls the 2 rear dc motors. It works fine at starting but eventually it swaps the coordinates. I send the X&Y coordinates but it process x data as Y and y data as X.

  • xAxis and yAxis is in the range of numbers 1-237 .
  • mappedxAxis is in the range of numbers 0-180.
  • mappedy1 and mappedy2 is in the range of numbers 0-255.



Do you have any suggestion to solve this problem?

I've tried sending the coordinates on the app blocks as : X data + 'X' and Y data + 'Y' and write a code to process this sorted data. The purpose of this idea was to solve the 'coordinate swap' bug by adding 'X' and 'Y' characters at the end of the coordinate data. For example:

  • Send 145X as coordinate data.
  • If data contains 'X' char make nsure that data will be proceeded as x coordinate.
  • Throw that 'X' at the end of the string.
  • Convert string to int.
  • Map x data in the range of 0-255
    Here is the arduino code:
    alternate soln.txt (696 Bytes)

Idea was pretty simple but it doesn't even work :expressionless: