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

Dependencies:   mbed

Fork of 02_LAB_serial_protocol by ferney alberto beltran molina

Revision:
10:d2bf51fdc68a
Child:
11:8055e81e45d1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/draw.cpp	Wed Oct 11 23:09:44 2017 +0000
@@ -0,0 +1,87 @@
+
+#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(1);
+}
+
+void nodraw(){
+myServoZ.pulsewidth_us(MAXPOS);
+wait(1);
+}
+
+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();
+ 
+}
\ No newline at end of file