エレキジャックweb mbed入門 サーボモータ 課題1です。サーボを左右に動かします。

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //Servo test01
00002 // Servo basic test
00003 #include "mbed.h"
00004 #include "TextLCD0420.h"
00005 
00006 #define ON 1
00007 #define OFF 0
00008 
00009 DigitalOut mled0(LED1);
00010 DigitalOut mled1(LED2);
00011 AnalogIn vr_adc(p15);
00012 PwmOut servo1(p21);
00013 
00014 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3
00015 
00016 int main() {
00017   float pwidth;
00018   lcd.cls();
00019   lcd.locate(0,0);
00020   lcd.printf("*** Servo test ****\n");         
00021   servo1.period_ms(20);// pulse cycle = 20ms
00022 
00023   while(1){   
00024     for(pwidth=0.001; pwidth<=0.002; pwidth+=0.0001) { // 1ms ~ 2ms
00025       servo1.pulsewidth(pwidth); // pulse servo out
00026       lcd.locate(0,1);
00027       lcd.printf("PulseWidth:%2.5f%",pwidth);
00028       wait(0.25);
00029     }
00030   }//while    
00031 }//main      
00032