Closed photodude closed 5 years ago
hiya thanks for the contribution
before we can merge, please fix up travis so it compiles/passes :) https://travis-ci.com/adafruit/Adafruit-PWM-Servo-Driver-Library/builds/133676811 also please add a short example demonstrating how you expect this function to be used
@ladyada travis is fixed now (I thought I had read over the code better than that before submitting, c'est la vie)
As for an example. I'm rewriting the RB-ENantel/RC_ESC to use the Adafruit PCA9685 PWM servo driver. The RB-ENantel/RC_ESC library currently uses the Arduino servo library to talk to Electronic Speed Controllers (ESC) and all of the functions are dependent on the Arduino servo library writeMicroseconds()
by including a writeMicroseconds()
function here it makes modifying libraries that depend on the Arduino servo library a simpler process.
function is used by calling pwm.writeMicroseconds(Pin, microseconds);
to set the pulse length in microseconds and not ticks. Example pwm.writeMicroseconds(0, 1000);
would make a 1000 microsecond pulse on pin 0 of the PWM/Servo driver the library is attached to (0x40).
pwm.writeMicroseconds(15, 2500);
would make a 2500 microsecond pulse on pin 15 of the PWM/Servo driver the library is attached to (0x40).
this mimics the arduino servo.writeMicroseconds(1000);
method which would write a 1000us pulse to the pin the library instance was attached to.
There is probably a better way to calculate the frequency from the prescale, I just attempted to reverse what was done in the setPWMFreq()
function.
awesome! great work :) please ping us when the example is added
@ladyada I take it from your response I need include something in the code examples folder showing use of this function.
Would it be sufficient if I extend the existing servo example with this new function?
yep! that sounds good
@ladyada the Servo example is now extended to include writeMicroseconds().
nice! what hardware did you test with?
@ladyada Tested with an arduino Uno, a Flycolor ESC, a 950KV motor. Was able to correctly arm and control the motor speed.
writeMicroseconds()
function for use in libraries that use standard Arduino servo library and want to convert to this breakout board. (currently modifying an ESC library for use with this breakout board)The function is based on the example servo sketch's
setServoPulse()
methodsetServoPulse()
method outputsDescribe any known limitations with your change.
setServoPulse()
method)0
valuePlease run any tests or examples that can exercise your modified code.
setServoPulse()
method; but uses the chip frequency not a hardcoded value, and takes microseconds as the input unlike thesetServoPulse()
method which used seconds.