a

Dependents:   3servotest 1stcomp 3rdcompfixstart 2ndcomp ... more

Fork of Servo by Tk A

servo.cpp

Committer:
choutin
Date:
2016-09-07
Revision:
1:c8ecfd809e22
Parent:
0:655e1fcb96be
Child:
2:442fae3b1c0e
Child:
3:c112df463a8d

File content as of revision 1:c8ecfd809e22:

#include "mbed.h"

PwmOut pwmarm(PC_6);
PwmOut pwmhand(PC_8);
PwmOut pwmbelt(PC_9);
float PERIOD=20000;

void armdegree(int degree) {
    int i;

   pwmarm.period_ms(20);        //20ms
   
       degree=10;

       i=500+degree*1900/180;
       pwmarm.write(i/PERIOD); 
}

void handdegree(int degree) {
    int i;

   pwmarm.period_ms(20);        //20ms
   
       degree=10;

       i=500+degree*1900/180;
       pwmhand.write(i/PERIOD); 
       
}

void beltdegree(int degree) {
    int i;

   pwmarm.period_ms(20);        //20ms
   
       degree=10;

       i=500+degree*1900/180;
       pwmbelt.write(i/PERIOD); 
       
}
void close_hand(void) {
     int i,degree;

    pwmhand.period_ms(20);        //20ms
    
        degree=175;

        i=500+degree*1900/180;
        pwmhand.pulsewidth_us(i); 
        
        
}

void close_arm(void) {
    int i,degree;

   pwmarm.period_ms(20);        //20ms
   
       degree=160;

       i=500+degree*1900/180;
       pwmarm.write(i/PERIOD); 
       
       
}


void open_hand(void) {
    int i,degree;

   pwmhand.period_ms(20);        //20ms
   
       degree=90;

       i=500+degree*1900/180;
       pwmhand.write(i/PERIOD); 
       
       
}



void open_arm(void) {
    int i,degree;

   pwmarm.period_ms(20);        //20ms
   
       degree=10;

       i=500+degree*1900/180;
       pwmarm.write(i/PERIOD); 
       
       
}