Andres Castañeda / Mbed 2 deprecated 01-01servos

Dependencies:   mbed

Fork of 01-01SolucionFuncionXY by ferney alberto beltran molina

main.cpp

Committer:
andrescas
Date:
2018-09-04
Revision:
5:9d27f2f6b1dc
Parent:
4:29a8b1df7fe2

File content as of revision 5:9d27f2f6b1dc:

#include "mbed.h"
#define MAXPOS 180       // en milimetros
#define SS_TIME 100     // en microsegundos
#define POSDRAW 10      

PwmOut myServo1(PB_3);
PwmOut myServo2(PB_4);
PwmOut myServo3(PB_5);
PwmOut myServo4(PB_8);
PwmOut myServo5(PB_8);
PwmOut myServo6(PA_5);
PwmOut myServo7(PA_6);
PwmOut myServo8(PA_7);

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

}
void mov1(float A){
    int pulseA = coord2us(A);      
    myServo1.pulsewidth_us(pulseA);
    wait_ms(SS_TIME);
}
void mov2(float b){
    int pulseb = coord2us(b);      
    myServo2.pulsewidth_us(pulseb);
    wait_ms(SS_TIME);
}
void mov3(float c){
    int pulsec = coord2us(c);      
    myServo3.pulsewidth_us(pulsec);
    wait_ms(SS_TIME);
}
void mov4(float d){
    int pulsed = coord2us(d);      
    myServo4.pulsewidth_us(pulsed);
    wait_ms(SS_TIME);
}
void mov5(float e){
    int pulsee = coord2us(e);      
    myServo5.pulsewidth_us(pulsee);
    wait_ms(SS_TIME);
}
void mov6(float f){
    int pulsef = coord2us(f);      
    myServo6.pulsewidth_us(pulsef);
    wait_ms(SS_TIME);
}
void mov7(float g){
    int pulseg = coord2us(g);      
    myServo7.pulsewidth_us(pulseg);
    wait_ms(SS_TIME);
}
void mov8(float h){
    int pulseh = coord2us(h);      
    myServo8.pulsewidth_us(pulseh);
    wait_ms(SS_TIME);
}

int main() {
     // configuracion de  periodo
    myServo1.period_ms(20);
    myServo2.period_ms(20);
    myServo3.period_ms(20);
    myServo4.period_ms(20);
    myServo5.period_ms(20);
    myServo6.period_ms(20);
    myServo7.period_ms(20);
    myServo8.period_ms(20);
    int pos=0;
    int servmot=0;   
    while(1)
    {   //definir servo luego posicion
        servmot=1;
        pos=50;
        wait(2);
        if (servmot=1){
        mov1(pos);}
        
        if (servmot=2){
        mov2(pos);}
        
        if (servmot=3){
        mov3(pos);}
        
        if (servmot=4){
        mov4(pos);}
        
        if (servmot=5){
        mov5(pos);}
        
        if (servmot=6){
        mov6(pos);}
        
        if (servmot=7){
        mov7(pos);}
        
        if (servmot=8){
        mov8(pos);}
     }

}