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.
main.cpp
- Committer:
- camilobar
- Date:
- 2017-09-16
- Revision:
- 0:e08430df04a4
File content as of revision 0:e08430df04a4:
#include "mbed.h"
#define MAXPOS 50
#define SS_TIME 500
PwmOut myServoX(PB_3);
PwmOut myServoY(PB_4);
PwmOut myServoZ(PB_5);
int coord2us(float coord)
{
if(0 <= coord <= MAXPOS)
return int(750+coord*1900/50);//
return 750;
}
void vertex2d(float x, float y, float z){//llamado una funcion coordenada con variables decimal en x,y
int pulseX = coord2us(x);
int pulseY = coord2us(y);
int pulseZ = coord2us(z);
myServoX.pulsewidth_us(pulseX);
myServoY.pulsewidth_us(pulseY);
myServoZ.pulsewidth_us(pulseZ);
wait_ms(SS_TIME);
}
void home()
{
vertex2d(0 ,0,1);
}
void maxpos()
{
vertex2d(MAXPOS ,MAXPOS,0);
}
void diag()
{
vertex2d(15,0,0);
vertex2d(15,0,10);
vertex2d(15,20,10);
vertex2d(15,50,10);
vertex2d(15,50,0);
}
void diag2()
{
vertex2d(15,25,0);
vertex2d(15,25,10);
vertex2d(10,35,10);
vertex2d(0,50,10);
vertex2d(0,50,0);
}
void square(float x, float y, float l)
{
int i,j;
int p,t;
vertex2d(x,y,0);
wait(1);
vertex2d(x,y,10);
wait(1);
p=l;
i=p;
j=y;
vertex2d(i,j/2,10);
t=l;
j=t;
vertex2d(i,j,10);
p=l;
i=p;
vertex2d(x,j,10);
vertex2d(x,y,10);
vertex2d(x,y,0);
vertex2d(0,0,0);
}
void line(float Xi,float Xf,float Yi,float Yf){
int i,j;
i=Xi;
j=Yi;
vertex2d(Xi,Yi,0);
vertex2d(i,j,10);
wait(2);
i=Xf;
j=Yf;
vertex2d(i,j,10);
wait(2);
vertex2d(Xf,Yf,0);
vertex2d(0,0,0);
}
void circle(int X,int Y,int R){
float resolucion=10,i,j;
double PI=3.1416;
vertex2d(X,Y,0);
wait(1);
for (double angulo=0;angulo<=370;angulo =angulo+resolucion){
double radian=((angulo * PI)/180);
j=R * cos(radian);
i=R * sin(radian);
vertex2d(X+i,Y+j,10);
}
}
int main() {
// configuracion de periodo
myServoX.period_ms(10);
myServoY.period_ms(10);
myServoZ.period_ms(20);
while(1)
{
//home();
//wait(1);
diag2();
wait(1);
diag();
wait(1);
square(0,0,25);
wait(5);
//line(0,30,0,30);
//wait(5);
circle(35,20,8); //coordenada x y seguido del radio
wait(5);
}
}