Sample for Servomoter (used by LPC1768)
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:6c4856d10c9f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 24 17:00:55 2016 +0000 @@ -0,0 +1,27 @@ +//Servo test01 +// Servo basic test + +#include "mbed.h" + + +#define ON +#define OFF 0 + +PwmOut servo1(p23); + +int main() { + float pwidth; + servo1.period_ms(20);// pulse cycle = 20ms + + while(1){ + for(pwidth=0.001; pwidth<=0.003; pwidth+=0.000001) { // 1ms ~ 2ms + servo1.pulsewidth(pwidth); // pulse servo out + wait(0.001);} + + for(pwidth=0.003; pwidth>=0.001; pwidth-=0.000001) { // 1ms ~ 2ms + servo1.pulsewidth(pwidth); // pulse servo out + wait(0.001); + + } + }//while +}//main4 \ No newline at end of file