Takeuchi Kouichi
/
2bk0817_servo_test01
エレキジャックweb mbed入門 サーボモータ 課題1です。サーボを左右に動かします。
Diff: main.cpp
- Revision:
- 0:3aa8ec194a4e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 18 06:36:58 2011 +0000 @@ -0,0 +1,32 @@ +//Servo test01 +// Servo basic test +#include "mbed.h" +#include "TextLCD0420.h" + +#define ON 1 +#define OFF 0 + +DigitalOut mled0(LED1); +DigitalOut mled1(LED2); +AnalogIn vr_adc(p15); +PwmOut servo1(p21); + +TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3 + +int main() { + float pwidth; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("*** Servo test ****\n"); + servo1.period_ms(20);// pulse cycle = 20ms + + while(1){ + for(pwidth=0.001; pwidth<=0.002; pwidth+=0.0001) { // 1ms ~ 2ms + servo1.pulsewidth(pwidth); // pulse servo out + lcd.locate(0,1); + lcd.printf("PulseWidth:%2.5f%",pwidth); + wait(0.25); + } + }//while +}//main +