Sorry about a newbie. 1. what mening of:
if(Xstr[XstrLength-1] != '|'){
Xstr[XstrLength] = '|';
Xstr[XstrLength+1] = '\0';
- the setup:
char Xstr[60];
what means? and then:itoa(Yint,Ystr,10);
Code:
#include <VirtualWire.h>
//gamepad setup
int up_button = 2;
int down_button = 4;
int left_button = 5;
int right_button = 3;
int start_button = 6;
int select_button = 7;
int joystick_button = 8;
int joystick_axis_x = A0;
int joystick_axis_y = A1;
int buttons[] = {up_button, down_button, left_button, right_button, start_button, select_button, joystick_button};
void setup()
{
//gamepad setup
for (int i; i < 7; i++)
{
pinMode(buttons[i], INPUT);
digitalWrite(buttons[i], HIGH);
}
Serial.begin( 9600 );
//transmitter setup
vw_set_tx_pin(12); // Sets pin D12 as the TX pin
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}
int counter = 0;
int Xint;
int Yint;
char Xstr[60];
char Ystr[60];
void loop()
{
// Read and store Sensor data
Xint = analogRead(joystick_axis_x);
Yint = analogRead(joystick_axis_y);
// Convert integer data to Char array directly
itoa(Yint,Ystr,10);
itoa(Xint,Xstr,10);
int XstrLength = String(Xstr).length();
if(Xstr[XstrLength-1] != '|'){
Xstr[XstrLength] = '|';
Xstr[XstrLength+1] = '\0';
}
char combinedArray[String(Xstr).length() + String(Ystr).length() + 1];
sprintf(combinedArray, "%s%s", Xstr, Ystr);
vw_send((uint8_t *)combinedArray, strlen(combinedArray));
vw_wait_tx(); // Wait until the whole message is gone
Serial.println(combinedArray);
}