Paolo Sanna
/
PCA9685_Hello_World
demonstration program for the library created for PCA9685 PWM controller
Diff: main.cpp
- Revision:
- 0:305237ecbbe5
- Child:
- 1:9fd2d2f5184e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 22 13:23:02 2015 +0000 @@ -0,0 +1,48 @@ +/*PCA9685 library example code + *test library performed with two servomotor, attached in channel 0 and 1, that rotate to the right and to the left + */ +#include"PCA9685.h" +#include"mbed.h" + + + +PCA9685 pwm(D14,D15); + +void setServoPulse(uint8_t n, float pulse) { + float pulselength = 10000; // 10,000 units per seconds + pulse = 4094 * pulse / pulselength; + pwm.setPWM(n, 0, pulse); +} + +void initServoDriver() { + pwm.begin(); + pwm.setPrescale(64); //This value is decided for 10ms interval. + pwm.frequencyI2C(400000); //400kHz +} + +int main() { + + while(1){ + initServoDriver(); + wait(0.2); + setServoPulse(0, 2300); + setServoPulse(1, 500); + wait(0.5);//delay necessary to perform the action + setServoPulse(0, 1350); + setServoPulse(1, 1350); + wait(0.5); + setServoPulse(0,550); + setServoPulse(1, 2250); + wait(0.5); + setServoPulse(0, 2300); + wait(2); + for (int mov = 550; mov < 2300; mov++){ + setServoPulse(0, mov); + wait(0.001); + } + for (int mov = 500; mov < 2200; mov++){ + setServoPulse(1, mov); + wait(0.001); + } + } +} \ No newline at end of file