#include     <SPI.
h>
#include     <nRF24L01.h>
#include     <RF24.h>
#include     <Servo.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
Servo steeringServo;
Servo esc;
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();
    steeringServo.attach(6);
    esc.attach(5);
    esc.writeMicroseconds(1000); // Arm ESC (depends on ESC type)
    delay(2000);
}
void loop() {
  int data[2];
  if (radio.available()) {
    radio.read(&data, sizeof(data));
    int xVal = data[0]; // Steering
    int yVal = data[1]; // Throttle
        int angle = map(xVal, 0, 1023, 0, 180);        // Servo angle
        int speed = map(yVal, 0, 1023, 1000, 2000);    // ESC PWM range
        steeringServo.write(angle);
        esc.writeMicroseconds(speed);
    }
}