![](/media/cache/profiles/e5815151957be36ad2085b7a1a02c5cc.jpg.50x50_q85.jpg)
Sample program for Adafruit-PWM-Servo-Driver
Dependencies: Adafruit-PWM-Servo-Driver mbed
Diff: main.cpp
- Revision:
- 0:4323102e4255
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Aug 17 09:01:43 2013 +0000 @@ -0,0 +1,25 @@ +#include "mbed.h" +#include "Adafruit_PWMServoDriver.h" + +Adafruit_PWMServoDriver pwm(p9, p10); + +void setServoPulse(uint8_t n, float pulse) { + float pulselength = 10000; // 10,000 us per second + pulse = 4094 * pulse / pulselength; + pwm.setPWM(n, 0, pulse); +} + +void initServoDriver() { + pwm.begin(); + //pwm.setPWMFreq(100); //This dosen't work well because of uncertain clock speed. Use setPrescale(). + pwm.setPrescale(64); //This value is decided for 10ms interval. + pwm.setI2Cfreq(400000); //400kHz +} + +int main() { + //pwm.i2c_probe(); + initServoDriver(); + setServoPulse(0, 1000); + + while(1); +}