I build RC plane with arduino nano + nrf (2 servo and 1 ESC) esc I put in A3 and servo1 in A0, servo2 in A2 .. but only servo are employed, while esc does not work .. maybe I was wrong to write the value or sketchnya .. maybe you guys can help me where mistakes
// transmitter
#include <SPI.h>
#include "RF24.h"
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
int potpin_1 = A0;
int val_1;
int potpin_2 = A1;
int val_2;
int potpin_3 = A3;
int val_3;
void setup(void){
radio.begin();
radio.openWritingPipe(pipe);
}
void loop() {
val_1 = analogRead(potpin_1),val_1 = map(val_1, 0, 1023, 0, 127),msg[0] = val_1,radio.write(msg, 1);
val_2 = analogRead(potpin_2),val_2 = map(val_2, 0, 1023, 128, 255),msg[0] = val_2,radio.write(msg, 1);
val_3 = analogRead(potpin_3),val_3 = map(val_3, 0, 1023, 10, 10),msg[0] = val_3,radio.write(msg, 1);
}
And my Receiver
//
//
//
#include <Servo.h>
#include <SPI.h>
//
//
#include "RF24.h"
Servo servo1;
Servo servo2;
Servo servo3;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
int data;
int pos;
int throotle =50;
void setup()
{
servo1.attach(3);
servo2.attach(4);
servo3.attach(7);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop()
{
if (radio.available())radio.read(msg, 1);
if (msg[0] <128 && msg[0] >-1)data = msg[0], pos = map(data, 0, 127, 0, 177),servo1.write(pos);
if (msg[0] >127 && msg[0] <255)data = msg[0], pos = map(data, 128, 254, 9, 177),servo2.write(pos);
if (msg[0] <0 && msg[0] <255)data = msg[0], pos = map(data, 0, 1023, 1000, 3000),servo3.write(pos);
}