v0.1 : Servo Lib

Dependencies:   MeArm Servo mbed

Fork of wizArm_WIZwiki-W7500ECO by Ricky Kwon

main.cpp

Committer:
Ricky_Kwon
Date:
2016-02-22
Revision:
1:ab8c34738e00
Parent:
0:7a4088ccf3bc

File content as of revision 1:ab8c34738e00:

 // Hello World to sweep a servo through its full range
 
#include "mbed.h"
#include "Servo.h"
 
Servo myservo1(PC_9);
Servo myservo2(PC_8);
Servo myservo3(PC_4);
Serial pc(USBTX, USBRX);
int main() {    
    char Msg_c;
    pc.baud(115200);
    pc.printf("Hello Servo motor World!\r\n");
    float degree1, degree2, degree3 = 0;
    float degree = 0;
    
    while(1)
    {
        Msg_c = pc.getc();
        
        if(Msg_c==0x31)
        {
            degree = 0;
            pc.printf("1 : %f\r\n", degree);
            myservo1.position(degree);
            myservo2.position(degree);
            myservo3.position(degree);
        }
        else if(Msg_c=='a')
        {
            degree1+=2;
            pc.printf("a degree1 : %f\r\n", degree1);  
            myservo1.position(degree1);
        }
        else if(Msg_c=='s')
        {
            degree1-=2;
            pc.printf("s degree1 : %f\r\n", degree1);  
            myservo1.position(degree1);
        }
        else if(Msg_c=='z')
        {
            degree2+=2;
            pc.printf("z degree2 : %f\r\n", degree2);  
            myservo2.position(degree2);
        }
        else if(Msg_c=='x')
        {
            degree2-=2;
            pc.printf("x degree2 : %f\r\n", degree2);  
            myservo2.position(degree2);
        }
        else if(Msg_c=='c')
        {
            degree3+=2;
            pc.printf("c degree3 : %f\r\n", degree3);  
            myservo3.position(degree3);
        }
        else if(Msg_c=='v')
        {
            degree3-=2;
            pc.printf("v degree3 : %f\r\n", degree3);  
            myservo3.position(degree3);
        }
    }

}