TJPS

Dependencies:   Adafruit-PWM-Servo-Driver mbed

Fork of Adafruit-PWM-Servo-Driver_sample by Shundo Kishi

Committer:
syundo0730
Date:
Sat Aug 17 09:01:43 2013 +0000
Revision:
0:4323102e4255
Child:
2:a94e3ade9632
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
syundo0730 0:4323102e4255 1 #include "mbed.h"
syundo0730 0:4323102e4255 2 #include "Adafruit_PWMServoDriver.h"
syundo0730 0:4323102e4255 3
syundo0730 0:4323102e4255 4 Adafruit_PWMServoDriver pwm(p9, p10);
syundo0730 0:4323102e4255 5
syundo0730 0:4323102e4255 6 void setServoPulse(uint8_t n, float pulse) {
syundo0730 0:4323102e4255 7 float pulselength = 10000; // 10,000 us per second
syundo0730 0:4323102e4255 8 pulse = 4094 * pulse / pulselength;
syundo0730 0:4323102e4255 9 pwm.setPWM(n, 0, pulse);
syundo0730 0:4323102e4255 10 }
syundo0730 0:4323102e4255 11
syundo0730 0:4323102e4255 12 void initServoDriver() {
syundo0730 0:4323102e4255 13 pwm.begin();
syundo0730 0:4323102e4255 14 //pwm.setPWMFreq(100); //This dosen't work well because of uncertain clock speed. Use setPrescale().
syundo0730 0:4323102e4255 15 pwm.setPrescale(64); //This value is decided for 10ms interval.
syundo0730 0:4323102e4255 16 pwm.setI2Cfreq(400000); //400kHz
syundo0730 0:4323102e4255 17 }
syundo0730 0:4323102e4255 18
syundo0730 0:4323102e4255 19 int main() {
syundo0730 0:4323102e4255 20 //pwm.i2c_probe();
syundo0730 0:4323102e4255 21 initServoDriver();
syundo0730 0:4323102e4255 22 setServoPulse(0, 1000);
syundo0730 0:4323102e4255 23
syundo0730 0:4323102e4255 24 while(1);
syundo0730 0:4323102e4255 25 }