Adafruit-PWM-Servo-Driver-Library icon indicating copy to clipboard operation
Adafruit-PWM-Servo-Driver-Library copied to clipboard

Convert to BusIO

Open caternuson opened this issue 3 years ago • 0 comments

For #91. Converts to BusIO usage. Also provides a fix for getPWM() which was broken.

Tested with servo example sketch which works same as before.

Also tested with this sketch to verify getPWM():

#include <Adafruit_PWMServoDriver.h>

#define SERVOMIN  200 // This is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  400 // This is the 'maximum' pulse length count (out of 4096)
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates

Adafruit_PWMServoDriver pwm;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // init
  pwm.begin();
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(SERVO_FREQ);

  // set/read tests for PWM
  pwm.setPWM(0, 0, SERVOMIN);
  Serial.print("SERVOMIN = "); Serial.println(SERVOMIN);
  Serial.print("PWM ON = "); Serial.println(pwm.getPWM(0));
  Serial.print("PWM OFF = "); Serial.println(pwm.getPWM(0, true));

  pwm.setPWM(0, 0, SERVOMAX);
  Serial.print("SERVOMAX = "); Serial.println(SERVOMAX);
  Serial.print("PWM ON = "); Serial.println(pwm.getPWM(0));
  Serial.print("PWM OFF = "); Serial.println(pwm.getPWM(0, true));  

}

void loop() {
  pwm.setPWM(0, 0, SERVOMIN);
  delay(500);
  pwm.setPWM(0, 0, SERVOMAX);
  delay(500);
}

which outputs:

SERVOMIN = 200
PWM ON = 0
PWM OFF = 200
SERVOMAX = 400
PWM ON = 0
PWM OFF = 400

caternuson avatar Sep 06 '22 22:09 caternuson