i want to use the nRF24L01+ module to transmit the signal about themessage of 2-Axis Joystick module ,i try to add a variable to contain the valuable of the massage about X_PIN and Y_PIN,but it seems like it couldn't transmit the massage apart from the type of char
and my code
about transmit
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const int SW_pin = 6; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
int a,b,c;
//create an RF24 object
RF24 radio(9, 8); // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
void setup()
{
//pinMode(SW_pin, INPUT);
//digitalWrite(SW_pin, HIGH);
radio.begin();
//set the address
radio.openWritingPipe(address);
//Set module as transmitter
radio.stopListening();
Serial.begin(9600);
}
void loop()
{
//Send message to receiver
const char text[] = "switch: ";
a=digitalRead(SW_pin);
b=analogRead(Y_pin);
c=analogRead(X_pin);
radio.write(&text, sizeof(text));
radio.write(&a,sizeof(a));
radio.write(&c,sizeof(c));
radio.write(&b,sizeof(b));
delay(1000);
}
and about the receiver
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//create an RF24 object
RF24 radio(9, 8); // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
void setup()
{
while (!Serial);
Serial.begin(9600);
radio.begin();
//set the address
radio.openReadingPipe(0, address);
//Set module as receiver
radio.startListening();
}
void loop()
{
//Read the data if available in buffer
if (radio.available())
{
char text[32] = {0};
int a;
int c;
int b;
radio.read(&text, sizeof(text));
radio.read(&a, sizeof(a));
radio.read(&c, sizeof(c));
radio.read(&b, sizeof(b));
Serial.println(text);
Serial.println(a );
Serial.print(c );
Serial.println(b );
}
}