I need help to transmit four data for a joystick, to arduino to another arduino via RF antennas, I don't know how to send it in an effective manner. PLEASE help me!
I have used these modules before as well, they are quite good.
You need to have some kind of protocol defined for your communication, especially if you want to expand it to other commands like buttons, etc.
But to get you started, this code will send the number as 2 bytes across, and on the other side it will wait until it has 2 bytes, and then combine them to get the value. Ideally you need to add start bytes and end bytes, and perhaps even checksums into your data so that if the packets do not come across 100% that you can discard them and wait for a complete packet. The code I am giving you could get out of sync if one of the bytes are lost, and the other goes through successfully.
On the Transmitter side:
joystick1 = analogRead (A0); / / 0000 to 1024
Serial3.write(joystick1 >> 8); //write writes the actual byte value, as opposed to the string representation of the number
Serial3.write(joystick1);
On the Receiver side:
if (Serial.available() >= 2) { //wait until we have at least 2 bytes in the buffer to read.
joystick1 = (((unsigned int)Serial.read()) << 8) + Serial.read(); //reconstruct it from the 2 bytes
// do something with the value here.
}