testando

Dependencies:   mbed TextLCD2

Revision:
43:cfc3da0299ff
Parent:
42:a6fbbe536814
Child:
44:f0b7a2fe28d9
--- a/main_PM.cpp	Thu May 28 16:52:29 2020 +0000
+++ b/main_PM.cpp	Thu May 28 21:50:31 2020 +0000
@@ -27,7 +27,7 @@
 DigitalIn fdc_z(PC_12);
 
 //Iterrupcao botao de emergência
-InterruptIn emergencia_botao(PC_14);
+InterruptIn interrupcao(PC_14);
 
 //pinos do rele, saida digital para acionar o rele se necessario, dada uma entrada no pino da emergencia 
 DigitalOut rele1(PC_5);
@@ -67,20 +67,20 @@
 BusOut eixoz(PC_9,PC_8,PB_8,PC_6);
 
 //funcao para receber inputs do teclado
-char *pega_tecla(){
-        if (b == 0)return ("A");
-        if (a == 0)return("B");
-        if (t_0 == 0)return("0");
-        if (t_1 == 0)return("1");
-        if (t_2 == 0)return("2");
-        if (t_3 == 0)return("3");
-        if (t_4 == 0)return("4");
-        if (t_5 == 0)return("5");
-        if (t_6 == 0)return("6");
-        if (t_7 == 0)return("7");
-        if (t_8 == 0)return("8");
-        if (t_9 == 0)return("9");
-        return("nada");}
+char pega_tecla(){
+        if (b == 0)return ('A');
+        if (a == 0)return('B');
+        if (t_0 == 0)return('0');
+        if (t_1 == 0)return('1');
+        if (t_2 == 0)return('2');
+        if (t_3 == 0)return('3');
+        if (t_4 == 0)return('4');
+        if (t_5 == 0)return('5');
+        if (t_6 == 0)return('6');
+        if (t_7 == 0)return('7');
+        if (t_8 == 0)return('8');
+        if (t_9 == 0)return('9');
+        return('nada');}
 
 //funcao de movimentacao dos motores
 void mov_x_menos(){for(int i = 0; i < 4; i++){eixox = antihor[i];wait(t_motor);coord_x -= (5.625*5/32)/360;est_x = 0;}}
@@ -92,7 +92,7 @@
 
 //Funcao de interrupcao
 void emergencia(){TextLCD lcd(D4, D5, D6, D7, D8, D9); 
-    while(emergencia_botao == 0){
+    while(interrupcao == 0){
         rele1 = 0;
         eixox = 0b0000;
         eixoy = 0b0000;
@@ -138,21 +138,15 @@
         lcd.locate(0,2);
         lcd.printf("sistema");
         lcd.locate(0,3);
-        lcd.printf("A - proximo");                
+        lcd.printf("A - proximo");
+        interrupcao.fall(&emergencia);             
     while(1) {
-        tecla = teclado.ReadKey(); 
+        tecla = pega_tecla(); 
         if(tecla == 'A' && status_tela == "zeramento"){
             zeramento();
             status_tela = "inicio";
             funcao_inicio();}
-        
-       int solta = 1;
-       tecla = teclado.ReadKey();               //leitura da tecla apertada
-       if(tecla == '\0') solta = 1;             //set the flag when all keys are released
-       if((tecla != '\0') && (solta == 1)) {    //if a key is pressed AND previous key was released
-         printf("%c\n", tecla);
-         solta = 0;                           //clear the flag to indicate that key is still pressed
-         wait(0.1);}
+
              /* tentativa de fazer o motor parar ao apertar algum dos fins de curso
         if(fdc_x == 0 || fdc_y == 0 || fdc_z == 0){
             for(int i = 0; i < 4; i++){eixox = parado[i];wait(t_motor);est_x = 1;}
@@ -199,7 +193,7 @@
             for(int i = 0; i < 4; i++){eixoy = parado[i];}
             for(int i = 0; i < 4; i++){eixoz = parado[i];}}
     
-        tecla = teclado.ReadKey();
+        tecla = pega_tecla();
         if(tecla =='1' && status_tela == "inicio"){
             funcao_pega1();
             wait(1);
@@ -211,7 +205,7 @@
             funcao_salvo2();
             status_tela = "salvo";}
         
-        tecla = teclado.ReadKey();    
+        tecla = pega_tecla();    
         if(tecla =='1' && status_tela =="salvo"){
             funcao_salvo_agree1();
             wait(1);
@@ -248,7 +242,7 @@
             funcao_salvo2();
             status_tela = "inicio";}      
         
-        tecla = teclado.ReadKey();    
+        tecla = pega_tecla();    
         if(tecla =='1' && status_tela =="salvo_confirmacao"){  
             funcao_salvo_agree_pos_aviso();
             //posicionar no local da pega salvo; (motor -> programa.pos_x_pega e motor -> programa.pos_y_pega)
@@ -274,7 +268,7 @@
             programa = 1;
             status_tela = "salvo";}   
             
-        tecla = teclado.ReadKey(); 
+        tecla = pega_tecla(); 
         if(tecla =='1' && status_tela =="salvo_pos_certo"){}//salva essa posição como correta
         else if(tecla =='2' && status_tela =="salvo_pos_certo"){}
         else if(tecla =='B' && status_tela =="salvo_pos_certo"){             
@@ -283,7 +277,7 @@
             funcao_salvo_agree2(); 
             status_tela = "salvo_confirmacao";}          
                       
-        tecla = teclado.ReadKey();    
+        tecla = pega_tecla();    
         if(tecla =='1' && status_tela =="novo"){
             funcao_pega_forma();
             status_tela ="forma";}
@@ -294,7 +288,7 @@
             int volume = 0;
             int multiplicador = 1; 
             while(continuar){   
-                tecla = teclado.ReadKey();
+                tecla = pega_tecla();
                 if(tecla!= 'A' && tecla!='B' && tecla!='C' && tecla!='D' && tecla!='#' && tecla != '*'){
                     volume = multiplicador*volume + (int)tecla;    
                     multiplicador*=10;
@@ -321,7 +315,7 @@
             funcao_inicio();
             status_tela = "inicio";}
             
-        tecla = teclado.ReadKey();    
+        tecla = pega_tecla();    
         if(tecla == '1' && status_tela == "forma"){
             funcao_pega_forma_quad();
             status_tela ="forma_quad";}
@@ -332,7 +326,7 @@
             funcao_pega_forma();
             status_tela = "novo";}
         
-        tecla = teclado.ReadKey();
+        tecla = pega_tecla();
         if(tecla == 'A' && status_tela == "forma_quad"){
             funcao_pega1();
             wait(1);
@@ -364,7 +358,7 @@
             funcao_pega_forma();
             status_tela = "forma";}
             
-        tecla = teclado.ReadKey();    
+        tecla = pega_tecla();    
         if(tecla == 'A' && status_tela == "pos_y"){
             funcao_pega1();
             wait(1);