I didn't expect for you to add anything. The code was to illustrate putting the data to be sent into a struct, sending the data, receiving the data and displaying the data. It took very little to add that functionality to your code.
I modified the code that I posted to send the angle values via a rf24 and wrote a program to receive and display the values. This sending and receiving code has been tested on 2 Uno boards running rf24 radios. The part of the code that acquires values and does the calculations is unchanged and not in the scope of the code that I am supplying. Mind pin numbers and baud rates.
Sender code that puts the data into the accelValues struct and sends the values.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const byte CE_PIN = 9;
const byte CSN_PIN = 10;
const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
// ********* declare a srtuct for the payload
struct AccelValues
{
int x;
int y;
int z;
} accelValues;
//Analog read pins
const int xPin = A0;
const int yPin = A1;
const int zPin = A2;
//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 265;
int maxVal = 402;
//to hold the caculated values
//int x;
//int y;
//int z;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setChannel(76); //76 library default
//RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3, 5); // delay, count
radio.openWritingPipe(slaveAddress);
}
void loop()
{
//read the analog values from the accelerometer
int xRead = analogRead(xPin);
int yRead = analogRead(yPin);
int zRead = analogRead(zPin);
//convert read values to degrees -90 to 90 - Needed for atan2
int xAng = map(xRead, minVal, maxVal, -90, 90);
int yAng = map(yRead, minVal, maxVal, -90, 90);
int zAng = map(zRead, minVal, maxVal, -90, 90);
//Caculate 360deg values like so: atan2(-yAng, -zAng)
//atan2 outputs the value of -π to π (radians)
//We are then converting the radians to degrees
// ******* and adding them to the payload struct
accelValues.x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
accelValues.y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
accelValues.z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);
// ******** send the struct
radio.write( &accelValues, sizeof(accelValues) );
//Output the caculations
// Serial.print("x=");
Serial.print(accelValues.x);
Serial.print(",");
delay(100);
//Serial.print("Y=");
Serial.print(accelValues.y);
Serial.print(",");
delay(100);
// Serial.print("z=");
Serial.print(accelValues.z);
Serial.println(",");
delay(100);
}
The code to receive and display the values.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const byte CE_PIN = 9;
const byte CSN_PIN = 10;
const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(CE_PIN, CSN_PIN);
struct AccelValues
{
int x;
int y;
int z;
} accelValues;
bool newData = false;
//===========
void setup()
{
Serial.begin(9600);
Serial.println("SimpleRx Starting");
radio.begin();
radio.setChannel(76); //76 library default
//RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
}
void loop()
{
getData();
showData();
}
void getData()
{
if ( radio.available() )
{
radio.read( &accelValues, sizeof(accelValues) );
newData = true;
}
}
void showData()
{
if (newData == true)
{
Serial.print("Data received >> ");
Serial.print("X = ");
Serial.print( accelValues.x);
Serial.print(" Y = ");
Serial.print( accelValues.y);
Serial.print(" Z = ");
Serial.println( accelValues.z);
newData = false;
}
}