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.
Dependencies: mbed
Fork of Piccolo_1C_Funciones by
main.cpp
- Committer:
- Vanessa620
- Date:
- 2017-10-06
- Revision:
- 2:f52a2c0dedb4
- Parent:
- 1:f246d2321c06
File content as of revision 2:f52a2c0dedb4:
#include "mbed.h" #include "math.h" #define MAXPOS 50 // maxposX : 5.5cm ; maxposY : 4.5cm #define SS_TIME 500 #define PI 3.1415926 PwmOut myServoX(PB_3); PwmOut myServoY(PB_4); PwmOut myServoZ(PB_10); int coord2us(float coord) { if(0 <= coord <= MAXPOS) return int(750+coord*1900/50);// u6 //return 750; } void vertex2d(float y) //, float y { // int pulseX = coord2us(x); int pulseY = coord2us(y); //myServoX.pulsewidth_us(pulseX); myServoY.pulsewidth_us(pulseY); wait_ms(SS_TIME); } void home() { vertex2d(0); } void maxpos() { vertex2d(MAXPOS); } /* void cuadrado(int x, int y, int l) { float a; float b; wait(2);vertex2d(a,b); printf("position x =%.2f\n",a); printf("position y =%.2f\n",b); a=a+l; wait(2);vertex2d(a,b); printf("position x =%.2f\n",a); printf("position y =%.2f\n",b); b=b+l; wait(2);vertex2d(a,b); printf("position x =%.2f\n",a); printf("position y =%.2f\n",b); a=a-l; wait(2);vertex2d(a,b); printf("position x =%.2f\n",a); printf("position y =%.2f\n",b); b=b-l; wait(2);vertex2d(a,b); printf("position x =%.2f\n",a); printf("position y =%.2f\n",b); vertex2d(x,y); // wait(2); a=x+l; vertex2d(a,y); //wait(2); b=y+l; vertex2d(a,b); //wait(2); vertex2d(x,b); // wait(2); vertex2d(x,y); } void diag() { wait(2);vertex2d(0,0); wait(2);vertex2d(10,10); wait(2);vertex2d(20,20); wait(2);vertex2d(30,30); wait(2);vertex2d(40,40);*/ /*wait(1);vertex2d(0,0); wait(1);vertex2d(40,0); wait(1);vertex2d(40,40); wait(1);vertex2d(0,40); wait(1);vertex2d(0,0); wait(1);vertex2d(10,0); wait(1);vertex2d(10,40); wait(1);vertex2d(20,40); wait(1);vertex2d(20,0); wait(1);vertex2d(30,0); wait(1);vertex2d(30,40); wait(1);vertex2d(40,40); wait(1);vertex2d(40,0); } void Pendiente(int x0,int y0,int x1,int y1) { float x; float y; float m; for(x=x0; x<=x1; x=x+1) { m=(y1-y0)/(x1-x0); y=m*(x-x0)+y0; vertex2d(x,y); printf("position x =%.2f\n",x); printf("position y =%.2f\n",y); } */ /* vertex2d(x0,y0); //wait(2); vertex2d(x1,y1); } void circle(float cx, float cy, float radio) { float y; float x; wait(2); vertex2d(cx,cy); for(double i=PI/2; i<=PI ;i=i+0.5) { x=radio*cos(i); y=radio*sin(i); vertex2d(cx-x,cy-y); printf("position x =%.2f\n",x); printf("position y =%.2f\n",y); } wait(1); for(double i=0; i<=PI/2 ;i+=0.5) { x=radio*cos(i); y=radio*sin(i); vertex2d(x+cx,y+cy); printf("position x =%.2f\n",x); printf("position y =%.2f\n",y); } for(double i=PI; i<=(3*PI)/2 ;i=i+0.5) { x=radio*cos(i); y=radio*sin(i); vertex2d(x+y,cx+cy); printf("position x =%.2f\n",x); printf("position y =%.2f\n",y); }*/ /* for(double i=3*PI/2; i<=2*PI ;i=i+0.1) { x=radio*cos(i); y=radio*sin(i); vertex2d(cx+x,cy-y); printf("position x =%.2f\n",x); printf("position y =%.2f\n",y); } } void Pendiente(int x0,int y0,int x1,int y1); */ int main() { // configuracion de periodo myServoX.period_ms(20); myServoY.period_ms(20); myServoZ.period_ms(20); while(1) { home(); wait(2); maxpos(); wait(2); home(); /* wait(3); //Pendiente(30,35,15,20); //Pendiente(15,20,0,35); //Pendiente(0,35,15,50); //wait(3); //Pendiente(15,50,30,35); //wait(3); wait(3); Pendiente(30,20,30,40); Pendiente(30,40,40,40); Pendiente(40,40,40,20); Pendiente(40,20,30,20); wait(3); Pendiente(20,0,50,0); Pendiente(50,0,50,10); Pendiente(50,10,30,15); cuadrado(0,0,10); wait(2); circle(30,0,15); wait(3); diag(); */ } }