Luis Miguel Lovera Salazar / Mbed 2 deprecated pwm

Dependencies:   mbed

Fork of 01-04EntregaPrimerCorte by ferney alberto beltran molina

mover.cpp

Committer:
MigueAut
Date:
2018-09-09
Revision:
3:e43babb84ff3
Parent:
1:526bdd5faa37

File content as of revision 3:e43babb84ff3:


#include "mover.h"
#include "mbed.h"
#include "math.h"


PwmOut myServo1(PB_3);
PwmOut myServo2(PB_4);
PwmOut myServo3(PB_5);


uint8_t  ss_time=50;     // tiempo  de espera para moverse 1 mm en microsegundos

void put_sstime(uint8_t vtime){
    ss_time=vtime;
    
}

int coord2us(float coord)
{
    if(0 <= coord <= 180)
        return int(750+coord*1900/180);// u6
    return 750;

}


 


void mover_ser(uint8_t nmotor, uint8_t grados){
  int pulseX = coord2us(grados);
  switch(nmotor){
  case 0x01:
    myServo1.pulsewidth_us(pulseX);
    break;
    case 0x02:
    myServo2.pulsewidth_us(pulseX);
    break;
    case 0x03:   
    myServo3.pulsewidth_us(pulseX);
    break;}
}


void init_servo()
{
   myServo1.period_ms(20);
   myServo2.period_ms(20);
   myServo3.period_ms(20);

    
}