Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 01-01SolucionFuncionXY by
Revision 5:9d27f2f6b1dc, committed 2018-09-04
- Comitter:
- andrescas
- Date:
- Tue Sep 04 01:34:37 2018 +0000
- Parent:
- 4:29a8b1df7fe2
- Commit message:
- servos
Changed in this revision
01-01Solucionfuncionservo.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/01-01Solucionfuncionservo.lib Wed Mar 07 00:43:55 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/fabeltranm/code/01-01SolucionFuncionXY/#fe8e265eaf6e
--- a/main.cpp Wed Mar 07 00:43:55 2018 +0000 +++ b/main.cpp Tue Sep 04 01:34:37 2018 +0000 @@ -1,63 +1,105 @@ #include "mbed.h" -#define MAXPOS 50 // en milimetros +#define MAXPOS 180 // en milimetros #define SS_TIME 100 // en microsegundos #define POSDRAW 10 -PwmOut myServoX(PB_3); -PwmOut myServoY(PB_4); -PwmOut myServoZ(PB_5); - +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/50);// u6 + return int(750+coord*1900/180);// u6 return 750; } - -void draw() -{ -myServoZ.pulsewidth_us(POSDRAW); -wait(1); +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 nodraw() -{ -myServoZ.pulsewidth_us(MAXPOS); -wait(1); +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 vertex2d(float x, float y){ - - int pulseX = coord2us(x); - int pulseY = coord2us(y); - - myServoX.pulsewidth_us(pulseX); - myServoY.pulsewidth_us(pulseY); +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 - myServoX.period_ms(20); - myServoY.period_ms(20); - myServoZ.period_ms(20); - int posx=0; - int posy=0; - draw(); + 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); - vertex2d(posx,posy); - posx+=10; - if (posx>50){ - posx=0; - nodraw(); - } - posy=posy; + 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);} } -} - +} \ No newline at end of file