Vanesa Lara Cruz / Mbed 2 deprecated serial-protocol-V2

Dependencies:   mbed

Fork of 02_LAB_serial_protocol by ferney alberto beltran molina

draw.cpp

Committer:
fabeltranm
Date:
2017-10-11
Revision:
11:8055e81e45d1
Parent:
10:d2bf51fdc68a
Child:
13:4226825e2060

File content as of revision 11:8055e81e45d1:


#include "draw.h"
#include "mbed.h"

DigitalOut led(LED1);

PwmOut myServoX(PB_3);
PwmOut myServoY(PB_4);
PwmOut myServoZ(PB_5);


void led_on(uint16_t ts, uint16_t tms )
{

                led=1;  
                wait(ts);wait_ms(tms);
                led=0;   
                 
}

int coord2us(float coord)
{
    if(0 <= coord <= MAXPOS)
        return int(750+coord*1900/50);// u6
    return 750;

}

void draw(){
myServoZ.pulsewidth_us(POSDRAW);
wait_ms(SS_TIME);
}

void nodraw(){
myServoZ.pulsewidth_us(MAXPOS);
wait_ms(SS_TIME);
}

void vertex2d(uint8_t x, uint8_t y){

    int pulseX = coord2us(x);
    int pulseY = coord2us(y);
    
    myServoX.pulsewidth_us(pulseX);
    myServoY.pulsewidth_us(pulseY);
    wait_ms(SS_TIME); //TODO: CALCULAR EL TIEMPO DE DONDE  VIENE 

}

void initdraw(float x, float y){
    vertex2d (x,y);
    draw();
}

void home(){
    nodraw();
    vertex2d(0 ,0);
}    



void line(float xi, float yi, float xf,  float yf)
{   
    float xp; float yp;
    float m= (yf-yi)/(xf-xi);
    float b=yf-m*xf;
    
    initdraw(xi,yi);
    for (xp =xi;xp<=xf;xp+=RSTEP)
        {
         yp =m*xp+b;
         vertex2d(xp,yp);
        }
    nodraw();
 
}


void rectangle(float x, float y, float width,float height) {
    
    initdraw(x,y);
    
    vertex2d(x+width, y);
    vertex2d(x+width, y+height);
    vertex2d(x, y+height);
    vertex2d(x, y);
    
    nodraw();
 
}

void circle(float x, float y, float radio)
{
 initdraw(x+r,y);
 // coloque codigo aca 
 nodraw();

}