Transmitter:
//on MEGA
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24_config.h>
#define Rstick_y A2
#define CE_PIN 8
#define CSN_PIN 53
RF24 radio(CE_PIN, CSN_PIN);
byte addresses[][6] = {"1Node"};
struct positionData
{
byte Raxis_y;
};
positionData data;
void setup()
{
Serial.begin(115200);
Serial.println("Starting");
radio.begin();
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(addresses[0]);
}
void loop()
{
Serial.print("BEGIN");
data.Raxis_y = analogRead(Rstick_y); //read the joystick
radio.stopListening(); //is this part needed for transmitter?
radio.write( &data, sizeof(unsigned long) );
Serial.print(" Ryaxis: "); Serial.println(data.Raxis_y);
}
the "data.Raxis_y" reads values from 0 to 255. why isnt it reading values from 0 to 1023 like a joystick?
Reciever
//reciever will have the motors
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24_config.h>
#define CE_PIN 7
#define CSN_PIN 8
RF24 radio(CE_PIN, CSN_PIN);
byte addresses[][6] = {"1Node"};
struct positionData{
byte Raxis_y;
};
positionData data;
void setup(){
Serial.println("Starting");
Serial.begin(115200);
radio.begin(); //Link The Radio
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1, addresses[0]);
radio.startListening();
}
void loop()
{
if ( radio.available() )
{
while (radio.available()){
radio.read( &data, sizeof(unsigned long) );
}
int right_y = data.Raxis_y;
Serial.print(" RightJoystick: ");
Serial.print(right_y);
}
else{
Serial.println("LOST");
}
}
it keeps print LOST, what am i doing wrong?