サーボをPCで操作できるやつ

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut myled(LED1);
00004 PwmOut m(PA_9);
00005 Serial pc(USBTX,USBRX);
00006 
00007 #if 1
00008 int main(){
00009     m.period_ms(20);
00010     int pw=1500;
00011     while(1){
00012 
00013        char input = pc.getc();
00014        if(input == 'w'){
00015            pw+=50;
00016        }else if(input == 's'){
00017            pw-=50;
00018        }
00019        printf("%d\r\n",pw);
00020 
00021        m.pulsewidth_us(pw);
00022        
00023     }
00024 }
00025 #endif
00026 
00027 #if 0
00028 int main(){
00029     m.period_ms(20);
00030     
00031     while(1){
00032         m.pulsewidth_us(400);
00033         wait(1.5);
00034         m.pulsewidth_us(2550);
00035         wait(1.5);         
00036     }
00037 }
00038 #endif
00039 
00040 #if 0
00041 int main(){
00042     m.period_ms(20);
00043     
00044     while(1){
00045         m.pulsewidth_us(1000);
00046         wait(1.5);
00047         m.pulsewidth_us(2000);
00048         wait(1.5);         
00049     }
00050 }
00051 #endif