Pca 9685
Pca 9685
h>
#include <Adafruit_PWMServoDriver.h>
int pulse_;
int sv_;
int last_pulse;
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150 // This is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // This is the 'maximum' pulse length count (out of 4096)
#define USMIN 600 // This is the rounded 'minimum' microsecond length based on the
minimum pulse of 150
#define USMAX 2400 // This is the rounded 'maximum' microsecond length based on
the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates
void setup() {
Serial.begin(9600);
Serial.println("4 channel Servo test!");
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
delay(10);
}
// You can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. It's not precise!
void setServoPulse(uint8_t n, double pulse) {
double pulselength;
void loop() {
// Drive each servo one at a time using setPWM()
if(Serial.available())
{
String c = Serial.readString();
int ind=c.indexOf("s");
if(ind != -1)
{
Serial.println("ind:"+String(ind)+String(c[ind+1]));
int sv_ = c[ind+1]-(char)('0');
int pulse_ = c.substring(ind+2).toInt();
Serial.println("sv"+String(sv_)+" Pulse: "+String(pulse_));
pwm.setPWM(sv_, 0, pulse_);
}
}