prueba

Dependencies:   C12832 mbed

Fork of Vivoxie by J Daniel Martinez C

Revision:
0:149a086d663b
diff -r 000000000000 -r 149a086d663b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 21 21:37:41 2015 +0000
@@ -0,0 +1,315 @@
+#include "mbed.h"
+
+//PwmOut myled(LED1);
+//PwmOut myled2(LED2);
+//PwmOut myled3(LED3);
+//PwmOut myled4(LED4);
+        
+
+Serial Pc(USBTX, USBRX);
+Serial Pc2(p13,p14);
+///Configuracion de mano izquierda
+//Voice Coil
+            //Dedo medio buffer1 SLP
+DigitalOut voice1(p5);
+            //Dedo indice buffer2 SLP
+DigitalOut voice2(p6);
+            //Dedo pulgar buffer3 SLP
+DigitalOut voice3(p7);
+            //PWM buffer1,buffer2 y buffer3 
+PwmOut pwm_buffer123(p21);
+
+
+
+///Configuracion de mano izquierda
+//Celdas Peltier
+            //Dedo medio C1 SLP
+DigitalOut cel1(p8);
+            //Dedo indice C2 SLP
+DigitalOut cel2(p9);
+            //Dedo pulgar C3 SLP
+DigitalOut cel3(p10);
+            //PH 1,2 y 3        
+DigitalOut cel_PH123(p11);
+            //PWM C1,C2 y C3        
+PwmOut pwm_cel123(p23);
+
+ ///Configuracion de mano derecha
+//Voice Coil 
+            //Dedo medio V6
+DigitalOut voice6(p28);
+            //Dedo indice buffer5
+DigitalOut voice5(p29);
+            //Dedo pulgar buffer4
+DigitalOut voice4(p30);
+//PWM buffer4,buffer5 y V6
+PwmOut pwm_buffer456(p22);
+
+
+//Celdas Peltier
+            //Dedo medio C6 SLP
+DigitalOut cel6(p25);
+            //Dedo indice C5
+DigitalOut cel5(p26);
+            //Dedo pulgar C4
+DigitalOut cel4(p27);
+            //PH 4,5 y 6        
+DigitalOut cel_PH456(p12);
+            //PWM C4,C5 y C6        
+PwmOut pwm_cel456(p24);
+
+
+
+
+//Declaracion de variables 
+float x=0;      //variable de control de PWM y Frecuencia
+float j=0.3;    //variable PWM fijo Indice
+float h=0.3;    //variable PWM fijo Pulgar
+ 
+ ///Variables de temperatura
+ float caliente=0; 
+ float frio=0;
+ ///
+char Data[10],Tacto1[10],Temp1[10],ID1[10],Tacto2[10],Temp2[10],ID2[10];
+
+int buffer0,buffer1,buffer2,buffer3,buffer4,buffer5;
+
+char K[100];
+
+
+
+int main() {
+         Pc.baud(115200);
+         Pc2.baud(115200);
+    voice1=0;                       //desaHabilitamos SlP
+    cel1=0;    
+    voice2=0;                       //desaHabilitamos SlP
+    cel2=0;    
+    voice3=0;                       //desaHabilitamos SlP
+    cel3=0;        
+    voice4=0;                       //desaHabilitamos SlP
+    cel4=0;    
+    voice5=0;                       //desaHabilitamos SlP
+    cel5=0;    
+    voice6=0;                       //desaHabilitamos SlP
+    cel6=0;  
+
+
+    while(1) {
+       
+       if (Pc.readable())
+        {   
+           Pc.scanf("%s", &K);
+          
+          // Pc2.printf("%s\n ",&K);
+           //wait(5);
+           strcpy(Tacto1,   strtok(K , ","));
+           strcpy(Temp1,   strtok(NULL , ","));
+           strcpy(ID1,   strtok(NULL, ","));
+           strcpy(Tacto2,   strtok(NULL, ","));
+           strcpy(Temp2,  strtok(NULL, ","));
+           strcpy(ID2,  strtok(NULL, ","));
+           
+           buffer0 = atoi(Tacto1);
+           buffer1 = atoi(Temp1); 
+           buffer2 = atoi(ID1);     
+           buffer3 = atoi(Tacto2);
+           buffer4 = atoi(Temp2); 
+           buffer5 = atoi(ID2);
+           Pc2.printf("%i,%i,%i,%i,%i,%i\n\r",buffer0,buffer1,buffer2,buffer3,buffer4,buffer5);
+           wait(1);
+         }  
+       
+       
+       
+       
+        
+      
+        if(buffer2 == 58 )
+        {
+
+
+                ////////////Contacto//////////////////
+                if(buffer0 > 1 && buffer0<=65  ){  
+                x=(float( buffer0)-2)/63;         //Calculo de PWM variable
+                
+                 voice1=1;                       //Habilitamos SlP
+                 voice2=1;
+                 voice3=1;
+                pwm_buffer123.period_us (1);         //Se configura el periodo a 1MHz
+                pwm_buffer123 = x;                   // Mandamos el PWM
+                
+                Pc2.printf("Buffer0 ente 1 y 65\n\r");
+                wait(5);
+                }
+                ////////////Rugosidad///////////////////                                  
+                if( buffer0> 65 && buffer0<= 126 ){  
+                x=((float(( buffer0)-66)/60)*10000)+2000; //Calculo de frecuencia de periodo
+                 voice1=1;                       //Habilitamos SlP
+                 voice2=1;
+                 voice3=1;
+                pwm_buffer123.period_us (x);                    
+                pwm_buffer123 = j;                          //Configuracion de PWM Fijo
+                 
+                Pc2.printf("Buffer0 ente 65 y 126\n\r");
+                wait(5);
+                }
+                ////////////Vibracion//////////////////
+                if( buffer0>126 && buffer0<=255){  
+                x=(((float( buffer0)-127)/128)*75000)+10000; //Calculo de frecuencia de periodo
+                voice1=1;                       //Habilitamos SlP
+                 voice2=1;
+                 voice3=1;
+                pwm_buffer123.period_us (x);
+                pwm_buffer123 = j;                             //Configuracion de PWM Fijo
+                 
+                Pc2.printf("Buffer0 ente 126 y 255\n\r");
+                wait(5);
+                }
+                
+                
+                ////////////Temperatura///////////////         
+                if( buffer1 > 1 &&  buffer1 <= 63 ){
+                frio=((float( buffer1)-2)/-61)+1;         //Calculo de PWM
+                 cel1=1;
+                 cel2=1;
+                 cel3=1;
+                cel_PH123=1;                               //Cambio de polaridad de driver 
+                pwm_cel123=frio;
+                 
+                Pc2.printf("Buffer1 ente 1 y 63\n\r");
+                wait(5);
+                }
+                if( buffer1> 63 &&  buffer1<= 126 ){
+                caliente=(float( buffer1)-64)/124;        //Calculo de PWM
+                 cel1=1;
+                 cel2=1;
+                 cel3=1;
+                cel_PH123=0;                               //Cambio de polaridad de driver
+                pwm_cel123=caliente;
+                 
+                Pc2.printf("Buffer1 ente 63 y 126\n\r");
+                wait(5);
+                }
+                /////////////////////////////////////       //Poner a 0 PWM
+                
+                if( buffer1==0){
+                 cel1=0;
+                 cel2=0;
+                 cel3=0;
+                pwm_cel123=0;
+                 
+                Pc2.printf("Buffer1 = 0\n\r");
+                wait(5);
+                }
+                if( buffer0==0){
+                 voice1=0;                       //Habilitamos SlP
+                 voice2=0;
+                 voice3=0;
+                pwm_buffer123=0;
+                 
+                Pc2.printf("Buffer0 = 0\n\r");
+                wait(5);
+                }
+        }//end if
+///////////////////////////////////////////////////////
+
+    
+    //////////////////////////MANO Derecha/// Falange A//////////////
+            if(buffer5 == 74 ) {
+                
+                voice4=1;
+                voice5=1;
+                voice6=1;
+                cel4=1;
+                cel5=1;
+                cel6=1;
+                
+                ////////////Contacto//////////////////
+                if(buffer3> 1 && buffer3<=65  ) {
+                    x=(float( buffer3)-2)/63;         //Calculo de PWM variable
+                   
+                    voice4=1;
+                    voice5=1;
+                    voice6=1; 
+                    pwm_buffer456.period_us (1);         //Se configura el periodo a 1MHz
+                    pwm_buffer456 = x;                   // Mandamos el PWM
+                     
+                Pc2.printf("Buffer3 ente 1 y 65\n\r");
+                wait(5);
+                }
+                ////////////Rugosidad///////////////////
+                if( buffer3> 65 && buffer3<= 126 ) {
+                    x=((float(( buffer3)-66)/60)*10000)+2000; //Calculo de frecuencia de periodo
+                    voice4=1;
+                    voice5=1;
+                    voice6=1;
+                    pwm_buffer456.period_us (x);                    
+                    pwm_buffer456 = j;                          //Configuracion de PWM Fijo
+                     
+                Pc2.printf("Buffer3 ente 65 y 126\n\r");
+                wait(5);
+                }
+                ////////////Vibracion//////////////////
+                if( buffer3>126 && buffer3<=255) {
+                    x=(((float( buffer3)-127)/128)*75000)+10000; //Calculo de frecuencia de periodo
+                    voice4=1;
+                    voice5=1;
+                    voice6=1;
+                    pwm_buffer456.period_us (x);                    
+                    pwm_buffer456 = j;                          //Configuracion de PWM Fijo
+                     
+                Pc2.printf("Buffer3 ente 126 y 255\n\r");
+                wait(5);
+                }
+                ////////////Temperatura///////////////
+                if( buffer4> 1 &&  buffer4<= 63 ) {
+                    frio=((float( buffer4)-2)/-61)+1;         //Calculo de PWM
+                    cel4=1;
+                    cel5=1;
+                    cel6=1;
+                    cel_PH456=1;                               //Cambio de polaridad de driver 
+                    pwm_cel456=frio;
+                     
+                Pc2.printf("Buffer4 ente 1 y 63\n\r");
+                wait(5);
+                }
+                if( buffer4> 63 &&  buffer4<= 126 ) {
+                    caliente=(float( buffer4)-64)/124;        //Calculo de PWM
+                    cel4=1;
+                    cel5=1;
+                    cel6=1;
+                    cel_PH456=0;                               //Cambio de polaridad de driver
+                    pwm_cel456=caliente;
+                     
+                Pc2.printf("Buffer4 ente 63 y 126\n\r");
+                wait(5);
+                }
+                /////////////////////////////////////       //Poner a 0 PWM
+                if( buffer4==0) {
+                    cel4=0;
+                    cel5=0;
+                    cel6=0;
+                    pwm_cel456=0;
+                     
+                Pc2.printf("Buffer4 =0\n\r");
+                wait(5);
+                }
+                if( buffer3==0) {
+                    voice4=0;
+                    voice5=0;
+                    voice6=0;
+                    pwm_buffer456=0;
+                     
+                Pc2.printf("Buffer3 = 0\n\r");
+                wait(5);
+                }
+            }//end if
+///////////////////////////////////////////////////////end Indice
+    
+    
+    
+    
+    
+    }
+}
\ No newline at end of file