#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeOut = 0xE9E8F0F0E1LL; //IMPORTANT: The same as in the receiver 0xE9E8F0F0E1LL | Bu adres alıcı ile aynı olmalı
RF24 radio(9, 10); // select CE,CSN pin | CE ve CSN pinlerin seçimi
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
};
Signal data;
void ResetData(){
data.throttle = 12;
data.pitch = 127;
data.roll = 127;
data.yaw = 127;
data.aux1 = 127;
data.aux2 = 127;
}
void setup() {
radio.begin();
radio.begin();
radio.openWritingPipe(pipeOut);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_HIGH);
radio.stopListening(); //start the radio comunication for Transmitter | Verici olarak sinyal iletişimi başlatılıyor
ResetData();
}
int mapJoystickValues(int val,int lower,int middle,int upper)
{
val = constrain(val,lower,upper);
if(val < middle)
val = map(val,lower,middle,0,130);
else
val = map(val,middle,upper,130,255);
}
void loop() {
data.throttle = mapJoystickValues(analogRead(A0),1023,0,150);
data.roll = mapJoystickValues( analogRead(A3), 12, 524, 1020);
data.pitch = mapJoystickValues( analogRead(A2), 12, 524, 1020);
data.yaw = mapJoystickValues( analogRead(A1), 12, 524, 1020);
data.aux1 = mapJoystickValues( analogRead(A6), 12, 524, 1020);
data.aux2 = mapJoystickValues( analogRead(A7), 12, 524, 1020);
radio.write(&data, sizeof(Signal));
}