-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservos
More file actions
34 lines (27 loc) · 879 Bytes
/
servos
File metadata and controls
34 lines (27 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// Create an instance of the PCA9685 class
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// The servo is connected to channel 1 on the PCA9685
const int SERVO_CHANNEL = 1;
const int SERVO_CHANNEL2 = 4;
// Set the minimum and maximum pulse widths for the servo
const int MIN_PULSE_WIDTH = 100;
const int MAX_PULSE_WIDTH = 550;
void setup() {
// Initialize the I2C bus and the PCA9685
Wire.begin();
pwm.begin();
// Set the PWM frequency to 50 Hz
pwm.setPWMFreq(50);
}
void loop() {
// Set the pulse width to the minimum value
pwm.setPWM(SERVO_CHANNEL, 0, MIN_PULSE_WIDTH);
pwm.setPWM(SERVO_CHANNEL2, 0, MIN_PULSE_WIDTH);
delay(1500);
// Set the pulse width to the maximum value
pwm.setPWM(SERVO_CHANNEL, 0, MAX_PULSE_WIDTH);
pwm.setPWM(SERVO_CHANNEL2, 0, MAX_PULSE_WIDTH);
delay(1500);
}