From cbdfb06c9964d66c93ab626109d4e5778a22854f Mon Sep 17 00:00:00 2001 From: gohai Date: Thu, 12 Jul 2018 13:27:30 -0700 Subject: [PATCH] IO: Add a dispose method to PCA9685 example, document pulse widths Developed together with @OlivierLD --- .../Servo_I2C_PCA9685/Servo_I2C_PCA9685.pde | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/java/libraries/io/examples/Servo_I2C_PCA9685/Servo_I2C_PCA9685.pde b/java/libraries/io/examples/Servo_I2C_PCA9685/Servo_I2C_PCA9685.pde index 3dd9f79ea..ede995bc5 100644 --- a/java/libraries/io/examples/Servo_I2C_PCA9685/Servo_I2C_PCA9685.pde +++ b/java/libraries/io/examples/Servo_I2C_PCA9685/Servo_I2C_PCA9685.pde @@ -7,8 +7,14 @@ void setup() { size(400, 300); //printArray(I2C.list()); servos = new PCA9685("i2c-1", 0x40); - servos.attach(0); - servos.attach(1); + + // different servo motors will vary in the pulse width they expect + // the lines below set the pulse width for 0 degrees to 544 microseconds (μs) + // and the pulse width for 180 degrees to 2400 microseconds + // these values match the defaults of the Servo library on Arduino + // but you might need to modify this for your particular servo still + servos.attach(0, 544, 2400); + servos.attach(1, 544, 2400); } void draw() { @@ -28,3 +34,8 @@ void draw() { y = map(angle, 0, 180, 0, height); line(width/2, y, width, y); } + +void dispose() { + servos.detach(0); + servos.detach(1); +}