Vanesa Lara Cruz / Mbed 2 deprecated jc

Dependencies:   mbed

Fork of jc by Sist. Piccolo

Revision:
3:c14aa9395c2a
Parent:
2:773082426491
--- a/main.cpp	Fri Nov 24 21:19:29 2017 +0000
+++ b/main.cpp	Fri Nov 24 23:17:49 2017 +0000
@@ -2,7 +2,8 @@
 #include "mbed.h"
 #include "math.h"
 #include "cstdlib"
-
+#include "InterruptIn.h"
+ 
 //--------------------------DECLARACON DE CONTANTES-------------------------------
 #define MAXPOS 255
 #define SS_TIME 500
@@ -17,11 +18,11 @@
 PwmOut myServoX(PB_3); //MOTOR EJE X
 PwmOut myServoY(PB_4); //MOTOR EJE Y
 PwmOut myServoZ(PB_10);//MOTOR EJE Z
-
-InterruptIn mybutton2(PA_0);
+ 
+InterruptIn boton(PC_0);
 InterruptIn mybutton(USER_BUTTON);
 Serial command(USBTX, USBRX); //COMUNICACION SERIAL
-Serial Sdebug(USBTX, USBRX); 
+Serial Sdebug(USBTX, USBRX);  //DEBUG SERIAL
 DigitalOut led(LED1);          //DECLARACION LED DE LA PLACA
  
 //---------------------------DEFINICION COMANDOS POR CONSOLA---------------------- 
@@ -36,11 +37,11 @@
 #define RESOLUCION 8
 #define HOME 9
 #define TIEMPO_DE_PASO 10
-
+ 
 //--------------------------LLAMADO RUTINA DE INTERRUPCIONES----------------------
 //Ticker ticker1; //Variable para rutina de interupciones
 //Timeout timeout;//Llamado de variable por conteo para manejo de pausa
-
+ 
 //-------------------------VARIABLES GLOBALES-------------------------------------
 int rap;//Pendiente 
 int RSTEP = 5;
@@ -49,7 +50,7 @@
 double k,l,r,tp=50,paso=0;
 int p=0;
 uint8_t estado = 0;
-
+ 
 //*****************************************************************************
 //  COMANDO  MOVER MOTOR
 //  |POS 1|POS 2|POS 3|POS 4| POS 5| POS 6| POS 7|
@@ -60,13 +61,13 @@
 // <,> -> inicio,  y fin de comando 
 //  el inicio de comando no se almacena en el buffer
 //*****************************************************************************
-
+ 
 //--------------------------DETERMINACION TAMAÑO DE BUFFER------------------------
 uint8_t buffer_command[BUFF_SIZE]={0,0,0,0,0,0};
 float buffer_POS [BUFF_POS]= {0,0,0,0,0,0};
-
+ 
 //--------------------FUNCIONES PARA COMANDO DE BUFFER----------------------------
-
+ 
 int coord2us(float coord)
     {
         if(0 <= coord <= MAXPOS)
@@ -148,7 +149,7 @@
           myServoZ.pulsewidth_us(pulseZ);
         wait_ms(SSTIME);
     }
-
+ 
 //--------------------------DECLARACION MEMORIA DE SERVOS-------------------------
 uint8_t  posx_old=0;     // posición anterior del eje X
 uint8_t  posy_old=0;     // posición anterior del eje Y
@@ -178,7 +179,7 @@
         wait(1);
         draw();
     }
-
+ 
 void resolucion(int res){
     RSTEP = res;
     #if DEBUG
@@ -318,11 +319,10 @@
       if(x2==r)
       {
       wait(1);  
-    }
     home();
     }
         
-        }
+}
 //-------------------------------FUNCION REANUDAR---------------------------------
     void reanudar(){
         
@@ -337,17 +337,20 @@
        led = !led;                            
        command.printf("piccolo en pausa \n");
        wait (5);
-       return; 
+       //return; 
        
     }
        
 //-------------------------------FUNCION PARE-------------------------------------            
 void stop() //Funcion para detener el programa  
     {
+    command.printf("piccolo en Stop \n");
+    home();  
     exit(0);
-    home();           
+    
+             
     }  
-
+ 
 void command_exe()
     {
         
@@ -370,7 +373,7 @@
                 command.printf("Dibujando Punto");
                 #endif
             break;
-
+ 
             case LINE:
                 #if DEBUG
                     command.printf("Dibujando Linea\n");
@@ -379,7 +382,7 @@
                 
                 
             break;
-
+ 
             case RECTANGLE: 
                 #if DEBUG
                     command.printf("Dibujando Rectangulo\n");
@@ -441,7 +444,7 @@
        
         }
 }
-
+ 
 //--------------------------***PENDIENTE***---------------------------------------
     void Rx_interrupcion(){
         
@@ -469,6 +472,7 @@
             Read_command();
             mybutton.fall(&pause);
             mybutton.rise(&reanudar);
+            boton.fall(&stop);
             if (check_command()){
                 command_exe();
             }
@@ -488,9 +492,4 @@
            }
           }
                      
-            }
-        
-                
-    
-    
-
+            }
\ No newline at end of file