#define numChannels 10
#define NUM_SERVOS 10
#include <ESP32Servo.h>
#include "BluetoothSerial.h"
//not sure if the following is needed; got it in an example piece of code
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif*
BluetoothSerial SerialBT;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
Servo myservo8;
Servo myservo9;
Servo myservo10;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32VixenServo"); //any name, your choice
//pinMode (11,OUTPUT);
//digitalWrite(11,HIGH);
myservo1.attach(2); // some pins interfere with the Serial Bluetooth
myservo2.attach(4); //Only pins 2,4,12-19,21-23,25-27,32-33 are recommended
myservo3.attach(12);
myservo4.attach(13);
myservo5.attach(32);
myservo6.attach(33);
myservo7.attach(25);
myservo8.attach(26);
myservo9.attach(27);
myservo10.attach(14);
myservo1.write(95); //neutral position
myservo2.write(95);
myservo3.write(95);
myservo4.write(95);
myservo5.write(95);
myservo6.write(95);
myservo7.write(95);
myservo8.write(95);
myservo9.write(95);
myservo10.write(95);
}
void loop() {
while (!SerialBT.available());
//set Vixen header to '~!'.
for ( ; ; )
{
if (SerialBT.read() == '~') {
break;
}
}
while (!SerialBT.available());
for ( ; ; )
{
if (SerialBT.read() == '!') {
break;
}
}
while (!SerialBT.available());
byte channelValues[numChannels];
for (byte iChn = 0; iChn < numChannels; iChn++)
{
while (!SerialBT.available());
channelValues[iChn] = SerialBT.read();
}
myservo1.write(map(channelValues[0], 0, 255, 89, 110)); //Schroeder 90-110
myservo2.write(map(channelValues[1], 0, 255, 90, 110)); //Patty 90-110
myservo3.write(map(channelValues[2], 0, 255, 90, 110)); //sally 90-110
myservo4.write(map(channelValues[3], 0, 255, 90, 110)); //Linus 90-110
myservo5.write(map(channelValues[4], 0, 255, 90, 110)); //PigPen 90-110
myservo6.write(map(channelValues[5], 0, 255, 85, 105)); //Frnklin 85-105
myservo7.write(map(channelValues[6], 0, 255, 90, 110)); //Lucy 90-110
myservo8.write(map(channelValues[7], 0, 255, 90, 110)); //Chuck 90-110
myservo9.write(map(channelValues[8], 0, 255, 75, 98)); //Snoopy 75-98
myservo10.write(map(channelValues[9], 0, 255, 90, 110));
//digitalWrite(11,channelValues[9]); // for relay for myservo power supply
}