123

Dependencies:   mbed

Fork of Boboobooo by Clark Lin

servo_api.cpp

Committer:
even
Date:
2014-07-07
Revision:
7:f04bde0ca846
Parent:
6:b046d6ff3745
Child:
9:a891053657f3

File content as of revision 7:f04bde0ca846:

// 0~180 angle    1~2ms
#include "mbed.h"
#include "servo_api.h"
#define right_end 1.0  //90
#define left_end 0.0  //-90

//memory opt
// 5 degree seperate
BX_servo::BX_servo(void)
{
    angle = 0;
    servo_in= new  PwmOut(PTB0);
    servo_in->period_ms(20);
}

float BX_servo::set_angle(float a)
{

    if( a<left_end )
        a=left_end;
    else if(a>right_end)
        a=right_end;
    angle=a;
    *servo_in=angle;

    return angle;
}