Created
February 14, 2025 02:05
-
-
Save sagarsapkota1/4bb598d712ee305e5ecb63494e8721f7 to your computer and use it in GitHub Desktop.
asic Arduino Code for PCA9685
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Wire.h> | |
| #include <Adafruit_PWMServoDriver.h> | |
| Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40); // Default I2C address | |
| #define SERVO_MIN 150 // Minimum pulse length | |
| #define SERVO_MAX 600 // Maximum pulse length | |
| void setup() { | |
| Serial.begin(115200); | |
| Serial.println("PCA9685 Test"); | |
| pwm.begin(); | |
| pwm.setPWMFreq(50); // Set frequency to 50Hz for servos | |
| delay(500); | |
| } | |
| void loop() { | |
| // Move servo from min to max | |
| for (int pos = SERVO_MIN; pos <= SERVO_MAX; pos += 10) { | |
| pwm.setPWM(0, 0, pos); // Set PWM on channel 0 | |
| delay(20); | |
| } | |
| // Move servo from max to min | |
| for (int pos = SERVO_MAX; pos >= SERVO_MIN; pos -= 10) { | |
| pwm.setPWM(0, 0, pos); | |
| delay(20); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment