When trying to control the esc with PWM from servo library it only lets me control 2 out of the 4 escs, It only generates the PWM signal to 2 out of 4 digital pins. How do I fix this?
#include <ESP32Servo.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
Servo esc1;
Servo esc2;
Servo esc3;
Servo esc4;
int throttle1;
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
struct Data_Package{
byte roll;
byte pitch;
byte throttle;
byte yaw;
};
Data_Package data;
unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;
void setup() {
Serial.begin(57600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setAutoAck(false);
radio.setDataRate(RF24_2MBPS);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
esc1.attach(6);
esc2.attach(5);
esc3.attach(4);
esc4.attach(3);
}
void loop(){
if (radio.available()) {
radio.read(&data, sizeof(Data_Package));
lastReceiveTime = millis();
}
currentTime = millis();
if ( currentTime - lastReceiveTime > 1000 ) {
};
throttle1 = map(data.throttle,90,180,1000,2000);
esc1.writeMicroseconds(throttle1);
esc2.writeMicroseconds(throttle1);
esc3.writeMicroseconds(throttle1);
esc4.writeMicroseconds(throttle1);
Serial.println(throttle1);