servo

Dependents:   followCar script_voor_project

Fork of Servo by Simon Ford

Servo.cpp

Committer:
backman
Date:
2016-12-02
Revision:
4:b9fe7af92cd5
Parent:
2:8995c167f399

File content as of revision 4:b9fe7af92cd5:

/* mbed R/C Servo Library
 *  
 * Copyright (c) 2007-2010 sford, cstyles
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
 
#include "Servo.h"
#include "mbed.h"


Servo::Servo(PinName pin) : _pwm(pin) {
    
    _pwm.period_ms(20);
    wait(0.5);
}



/*


  
    while(1){  
       
       p.pulsewidth(0.0010);
       wait(1);
       
        p.pulsewidth((0.0016+0.0009)/2);
       wait(1);
       
       p.pulsewidth(0.0015);
       wait(1);
       
   
   
     
  }

*/






void Servo::angle(float ang){
    
// l45->0.0010  1000us
// r45->0.0015  1500us 


//0.0010         0.0015
//  -45        0          45
         
//  m= 250/45 =5.556

//ang*x=    

    _pwm.pulsewidth_us(ang*5.556+1250);    
        
    
    
    
    
    
    
    
    
    
}