Skip to content

Commit cbdfb06

Browse files
committed
IO: Add a dispose method to PCA9685 example, document pulse widths
Developed together with @OlivierLD
1 parent cc46c5e commit cbdfb06

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

java/libraries/io/examples/Servo_I2C_PCA9685/Servo_I2C_PCA9685.pde

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ void setup() {
77
size(400, 300);
88
//printArray(I2C.list());
99
servos = new PCA9685("i2c-1", 0x40);
10-
servos.attach(0);
11-
servos.attach(1);
10+
11+
// different servo motors will vary in the pulse width they expect
12+
// the lines below set the pulse width for 0 degrees to 544 microseconds (μs)
13+
// and the pulse width for 180 degrees to 2400 microseconds
14+
// these values match the defaults of the Servo library on Arduino
15+
// but you might need to modify this for your particular servo still
16+
servos.attach(0, 544, 2400);
17+
servos.attach(1, 544, 2400);
1218
}
1319

1420
void draw() {
@@ -28,3 +34,8 @@ void draw() {
2834
y = map(angle, 0, 180, 0, height);
2935
line(width/2, y, width, y);
3036
}
37+
38+
void dispose() {
39+
servos.detach(0);
40+
servos.detach(1);
41+
}

0 commit comments

Comments
 (0)