cristian felipe carranza lopez / Mbed 2 deprecated pruebacondosservos

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"   //punto min 500 punto max 2400
00002 #define MAXPOS 50       // en milimetros
00003 #define SS_TIME 100     // en microsegundos
00004 PwmOut myServoZ(PB_3);  //eje_Z
00005 PwmOut myServoX(PB_4);  //eje_X
00006 PwmOut myServoY(PB_10); //eje_Y
00007 
00008 void NoDraw(){
00009     int pulseZ ;
00010     pulseZ=((1*35)+500);
00011     myServoZ.pulsewidth_us(pulseZ);
00012     wait_ms(SS_TIME);}
00013 
00014 void Draw(){
00015     int pulseZ ;
00016     pulseZ=((35*35)+500);
00017     myServoZ.pulsewidth_us(pulseZ);
00018     wait_ms(SS_TIME);}
00019 
00020 void vertex2d(float x, float y){
00021     int pulseX ;
00022     int pulseY ;
00023     pulseX=((x*35)+500);
00024     pulseY=((y*35)+500);
00025     myServoX.pulsewidth_us(pulseX);
00026     myServoY.pulsewidth_us(pulseY);
00027     wait_ms(SS_TIME);}
00028 
00029 int main() {
00030     myServoX.period_ms(20);
00031     myServoY.period_ms(20);
00032     myServoZ.period_ms(20);
00033     int posx=0;
00034     int posy=0;
00035     int ZZ=0;
00036     while(ZZ==0)
00037     {   wait(1);
00038         Draw();
00039         vertex2d(posx,posy);  
00040         posx+=10;posy+=10;
00041         if (posx>50) {posx=0;}
00042         if (posy>50) {posy=0;ZZ=1;}
00043     }
00044     while(ZZ==1){
00045         NoDraw();    
00046     }
00047 }