#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
const uint64_t pipeIn = 0xE8E8F0F0E1LL; //Remember that this code is the same as in the transmitter
RF24 radio(8, 7); //CSN and CE pins
// The sizeof this struct should not exceed 32 bytes
struct Received_data {
byte ch1;
};
int motor1_value = 0;
Received_data received_data;
Servo motor1;
/**************************************************/
void setup()
{
motor1.attach(10);
Serial.begin(9600);
//We reset the received values
received_data.ch1 = 127;
//Once again, begin and radio configuration
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,pipeIn);
//We start the radio comunication
radio.startListening();
}
/**************************************************/
unsigned long last_Time = 0;
//We create the function that will read the data each certain time
void receive_the_data()
{
while ( radio.available() ) {
radio.read(&received_data, sizeof(Received_data));
last_Time = millis(); //Here we receive the data
}
}
/**************************************************/
void loop()
{
//Receive the radio data
receive_the_data();
motor1_value = map(received_data.ch1,0,255,1000,2000);
Serial.println(motor1_value);
}//Loop end
Comments