AND / Mbed 2 deprecated HandHeld_Yudhi

Dependencies:   mbed

Revision:
5:3e17d7863de8
Parent:
3:3d51f8870e91
--- a/main.cpp	Fri Jul 26 09:31:58 2019 +0000
+++ b/main.cpp	Fri Jul 26 11:29:01 2019 +0000
@@ -17,7 +17,8 @@
 // Generated by: Mehrnaz Javadipour
 ////////////////////////// 
 
-Serial ttl(PC_12,PD_2);  //TTL cable TX,RX
+Serial ble(PC_12,PD_2);  //Bluetooth module TX,RX
+//If you like to use TTL cable instead, just change the above pins to: PA_2,PA_3 
 DigitalOut sol(PC_5);   //Solenoid: Digital Output
 PwmOut led(PB_6);
 
@@ -25,7 +26,7 @@
 
 int main()
 {
-    ttl.baud(9600); //baudrate for the serial connection
+    ble.baud(9600); //baudrate for the serial connection
     flow();         //calling flow from flow.h
     carbon();       //calling CO2 from flow.h
     s1();           //calling 8 channels from flow.h
@@ -77,7 +78,7 @@
     while(1)
     {
         led=1.00f;      //an LED is fully turned on at the beginning, the brightness will be reduced when the plateau is detected.
-        ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+        ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
 
         if (bf==0)      //finding base flow before breath
             {
@@ -88,7 +89,7 @@
                   }   
                fv=sf/4;
                fv=fv+0.2; 
-               //ttl.printf("set\n");
+               //ble.printf("set\n");
                bf=1;
              }
         
@@ -107,7 +108,7 @@
                 //I have also included printing the values inside the loops so we don't loose any data during calculatins.
                 for(m=0;m<9;m++)
                     {
-                        ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                        ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                         myArray[m]=carbon();
                     }
                 while(flags==0)
@@ -115,13 +116,13 @@
                         //While "flags" is enabled, keeps calculating the standard deviation.
                         for(int m=0;m<9;m++)
                             { 
-                            ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                            ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                             sum+=myArray[m]; 
                             }
                         avg=sum/9;
                         for(int m=0;m<9;m++)
                             {
-                            ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                            ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                             difSum+=(myArray[m]-avg)*(myArray[m]-avg); //Find sum of difference between value X and mean
                             }
                             var=difSum/9;
@@ -134,7 +135,7 @@
                             
                             for(int m=0;m<8;m++)
                              {
-                              ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                              ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                               myArray[m]=myArray[m+1];  //Shift all CO2 values to the left by 1 value
                              }
                              myArray[8]=carbon();  //assign a new value for the 9th sample
@@ -144,7 +145,7 @@
                              //Otherwise, it's accepted and will turn on the solenoid:
                             else
                             {
-                            ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                            ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                             sol=1;      //Solenoid is ON
                             led=0.50f;  //The brightness is reduced to half during the plateau
                             flags=1;    //breakes the while loop
@@ -159,20 +160,20 @@
         
                 for(m=0;m<9;m++)
                     {
-                        ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                        ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                         myArray[m]=carbon();
                     }
                 while(flage==0)
                     {
                         for(int m=0;m<9;m++)
                             { 
-                            ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                            ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                             sum2+=myArray[m]; 
                             }
                         avg2=sum2/9;
                         for(int m=0;m<9;m++)
                             {
-                            ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                            ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                             difSum2+=(myArray[m]-avg2)*(myArray[m]-avg2); 
                             }
                             var2=difSum2/9;
@@ -182,13 +183,13 @@
                             // here we defined the end threshold to be 0.05, it can be changed later based on experiment results
                             for(int m=0;m<8;m++)
                              {
-                              ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                              ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                               myArray[m]=myArray[m+1];  
                              }
                              myArray[8]=carbon();   
                             }else
                             {
-                            ttl.printf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
+                            ble.printf("temp:%f,flow:%f,co2:%f,s1:%f,s2:%f,s3:%f,s4:%f,s5:%f,s6:%f,s7:%f,s8:%f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8());
                             sol=0;  //Solenoid is OFF
                             flage=1;    //breakes the loop
                             }