I would also recommend slowing down the sender. I would send 20 to 50 times a second, that should be plenty. The more often that you send, the more power is required.
#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10); // nRF24L01 (CE, CSN)
const byte address[6] = "00001"; // Address
// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package
{
byte j1PotY;
byte j2PotX;
};
Data_Package data; //Create a variable with the above structure
void setup()
{
Serial.begin(9600);
pinMode(27, OUTPUT);
// Define the radio communication
radio.begin();
radio.openWritingPipe(address);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
radio.stopListening();
// Set initial default values
// Values from 0 to 255. When Joystick is in resting position,
//the value is in the middle, or 127. We actually map the pot value
//from 0 to 1023 to 0 to 255 because that's one BYTE value
data.j1PotY = 127;
data.j2PotX = 127;
Serial.println(sizeof(Data_Package));
}
void loop()
{
static unsigned long timer = 0;
unsigned long interval = 50; // 20 sends per second
if (millis() - timer >= interval)
{
timer = millis();
// Read all analog inputs and map them to one Byte value
data.j1PotY = map(analogRead(A0), 0, 1023, 0, 255);
data.j2PotX = map(analogRead(A1), 0, 1023, 0, 255); // changed to A1 from A2
Serial.print("Y axis = ");
Serial.print(data.j1PotY);
Serial.print(" X axis = ");
Serial.println(data.j2PotX);
// Send the whole data from the structure to the receiver
radio.write(&data, sizeof(Data_Package));
}
}
to learn about millis() for timing:
Several things at a time.
Beginner's guide to millis().
Blink without delay().