I want to control a servo using a joystick. There is no problem with the joystick, I checked. The serial monitor in the transmitter arduino is showing me proper angles. But the serial monitor of the receiver is not showing me the proper angles. Instead it's showing as shown in the screenshot below.
Here is the transmitter code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop()
{
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
delay(1000);
int potValue=analogRead(A2);
int angleValue=map(potValue,0,1023,0,180);
radio.write(&angleValue,sizeof(angleValue));
Serial.println(angleValue);
}
Here is the receiver code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop()
{
if (radio.available())
{
//delay(5);
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
int angleValue=0;
radio.read(&angleValue,sizeof(angleValue));
Serial.println(angleValue);
delay(5);
}
}
Here is the screenshot:
Could anyone tell me where I am going wrong?
