// RECEIVER
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(9, 10); // CE, CSN
Servo myServo;
const byte address[6] = "00001";
// Motor control pins
const int motorPinA = 6; // IN1
const int motorPinB = 7; // IN2
const int enablePin = 5; // ENA (PWM pin)
// Servo pin
const int servoPin = 3;
void setup() {
[Link](9600);
pinMode(motorPinA, OUTPUT);
pinMode(motorPinB, OUTPUT);
pinMode(enablePin, OUTPUT);
[Link](servoPin);
[Link]();
[Link](0, address);
[Link](RF24_PA_LOW);
[Link]();
}
void loop() {
if ([Link]()) {
int data[2];
[Link](&data, sizeof(data));
int speedVal = constrain(data[0], 0, 255); // Forward speed only
int servoVal = map(data[1], 0, 1023, 0, 180); // Servo angle
// Motor forward only
digitalWrite(motorPinA, HIGH);
digitalWrite(motorPinB, LOW);
analogWrite(enablePin, speedVal);
// Move servo
[Link](servoVal);
}
}