I'm trying to get servos to point 0, 90, and 180 degrees with MIT app inventor.
So the MIT app connects with to my Adafruit ESP32 V2 feather which has the 8 channel PWM servo wing, and they move.
As a newbie, I'm trying to adapt the example code for just 2 of the 8 servos but since I don't fully understand, they are not pointing correctly.
I need help with the Arduino code to receive the MIT text like B01, N01, and F01. So B will turn the servo fully clockwise, N would turn 90 and F would turn it fully counterclockwise. 00 to 07 would be the servos.
This is a copy of my Arduino code. Note that it currently receives number 1 to 6 but it will need to use my B01 (or I could use 1 for 0, 2 for 90, and 3 for 180. So 204 would turn servo number 5 to 90 degrees) if that technique makes it easier.
I'm just so frustrated, again.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150
#define SERVOMAX 600
#define USMIN 600
#define USMAX 2400
#define SERVO_FREQ 50
uint8_t servonum = 0;
void setup() {
SerialBT.begin("Esp32-BT");
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(SERVO_FREQ);
delay(10);
}
void setServoPulse(uint8_t n, double pulse) {
double pulselength;
pulselength = 1000000;
pulselength /= SERVO_FREQ;
Serial.print(pulselength); Serial.println(" us per period");
pulselength /= 4096;
Serial.print(pulselength); Serial.println(" us per bit");
pulse *= 1000000;
pulse /= pulselength;
Serial.println(pulse);
pwm.setPWM(n, 0, pulse);
}
void loop() {
if(SerialBT.available()){
char c = SerialBT.read();
Serial.println(servonum);
if(c == '1'){
pwm.setPWM(0, 0, 150);
}
if (c == '2'){
pwm.setPWM(0, 0, 475);
}
if (c == '3'){
pwm.setPWM(0, 0, 600);
}
if(c == '4'){
pwm.setPWM(1, 0, 150);
}
if (c == '5'){
pwm.setPWM(1, 0, 475);
}
if (c == '6'){
pwm.setPWM(1, 0, 600);
}
delay(500);
}
}
(``` added for indents - ABG)