POC Breath using SMD commercial sensors
Dependencies: iAQ_Core Adafruit_SGP30_mbed mbed BME680
main.cpp@6:f6faf142e5fc, 2020-05-01 (annotated)
- Committer:
- christodoulos
- Date:
- Fri May 01 11:58:59 2020 +0000
- Revision:
- 6:f6faf142e5fc
- Parent:
- 5:646a7e58989e
- Child:
- 7:f37620a76a1d
POC Breath using SMD commercial sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
christodoulos | 0:d034cdad5b6d | 1 | #include "mbed.h" |
mehrnaz | 2:ef98576cd67b | 2 | #include "flow.h" |
christodoulos | 5:646a7e58989e | 3 | #include <math.h> |
mehrnaz | 2:ef98576cd67b | 4 | ///////////////////////// |
mehrnaz | 3:3d51f8870e91 | 5 | // In this version of the program developed for the Breath project, flow and CO2, as well as 8 channel sensors, |
mehrnaz | 2:ef98576cd67b | 6 | // are measured in a separate .h file called: "flow.h" which is included in the |
mehrnaz | 3:3d51f8870e91 | 7 | // main code. So 10 sets of data is streamed using a serial connection (TTL cable or Bluetooth) |
christodoulos | 5:646a7e58989e | 8 | // without any intruption. |
mehrnaz | 2:ef98576cd67b | 9 | // This version is especially suitable to be used for KST. |
mehrnaz | 2:ef98576cd67b | 10 | // Also, a solenoid would be turned on and off based on calculating the standard deviation in CO2 profile. |
mehrnaz | 2:ef98576cd67b | 11 | // |
mehrnaz | 3:3d51f8870e91 | 12 | // START POINT: calculates SD for 9 samples of CO2, if it's grater than 0.02 it enables the solenoid. |
mehrnaz | 3:3d51f8870e91 | 13 | // END POINT: calculates SD for 9 samples of CO2, if it's grater thatn 0.05 it disables the solenoid. |
mehrnaz | 3:3d51f8870e91 | 14 | // |
mehrnaz | 3:3d51f8870e91 | 15 | // You can easily change the threshold of Standard deviation to detect plateau |
mehrnaz | 3:3d51f8870e91 | 16 | // |
mehrnaz | 2:ef98576cd67b | 17 | // Generated by: Mehrnaz Javadipour |
christodoulos | 5:646a7e58989e | 18 | ////////////////////////// |
christodoulos | 0:d034cdad5b6d | 19 | |
mehrnaz | 3:3d51f8870e91 | 20 | Serial ttl(PC_12,PD_2); //TTL cable TX,RX |
mehrnaz | 2:ef98576cd67b | 21 | DigitalOut sol(PC_5); //Solenoid: Digital Output |
mehrnaz | 3:3d51f8870e91 | 22 | PwmOut led(PB_6); |
christodoulos | 5:646a7e58989e | 23 | Timer stream; |
mehrnaz | 2:ef98576cd67b | 24 | |
mehrnaz | 2:ef98576cd67b | 25 | int main() |
christodoulos | 0:d034cdad5b6d | 26 | { |
christodoulos | 5:646a7e58989e | 27 | ttl.baud(115200); //baudrate for the serial connection, 9600 for hc05 115200 for rn |
christodoulos | 5:646a7e58989e | 28 | |
christodoulos | 5:646a7e58989e | 29 | ttl.printf("$");//enter command mode only for rn |
christodoulos | 5:646a7e58989e | 30 | wait(0.1); |
christodoulos | 5:646a7e58989e | 31 | ttl.printf("$$");//enter command mode |
christodoulos | 5:646a7e58989e | 32 | wait(0.5); |
christodoulos | 6:f6faf142e5fc | 33 | ttl.printf("SN,POC Breath\r");//set new name |
christodoulos | 5:646a7e58989e | 34 | wait(0.5); |
christodoulos | 5:646a7e58989e | 35 | ttl.printf("SS,C0\r");//set transparent uart |
christodoulos | 5:646a7e58989e | 36 | wait(0.5); |
christodoulos | 6:f6faf142e5fc | 37 | ttl.printf("&,6146DB234067\r");//Assign mac |
christodoulos | 6:f6faf142e5fc | 38 | wait(0.5); |
christodoulos | 5:646a7e58989e | 39 | ttl.printf("---\r");//enter data mode |
christodoulos | 5:646a7e58989e | 40 | wait(0.5); |
christodoulos | 5:646a7e58989e | 41 | |
mehrnaz | 2:ef98576cd67b | 42 | flow(); //calling flow from flow.h |
mehrnaz | 2:ef98576cd67b | 43 | carbon(); //calling CO2 from flow.h |
mehrnaz | 3:3d51f8870e91 | 44 | s1(); //calling 8 channels from flow.h |
mehrnaz | 3:3d51f8870e91 | 45 | s2(); |
mehrnaz | 3:3d51f8870e91 | 46 | s3(); |
mehrnaz | 3:3d51f8870e91 | 47 | s4(); |
mehrnaz | 3:3d51f8870e91 | 48 | s5(); |
mehrnaz | 3:3d51f8870e91 | 49 | s6(); |
mehrnaz | 3:3d51f8870e91 | 50 | s7(); |
mehrnaz | 3:3d51f8870e91 | 51 | s8(); |
mehrnaz | 3:3d51f8870e91 | 52 | getTemp(); //calling Temperature from flow.h |
christodoulos | 5:646a7e58989e | 53 | |
mehrnaz | 3:3d51f8870e91 | 54 | ////////////////////////////// |
mehrnaz | 3:3d51f8870e91 | 55 | // I defined a flag for each section of specific functions, so by enabling the |
mehrnaz | 3:3d51f8870e91 | 56 | // flag the section starts and by disabling the flag it finishes the section. |
christodoulos | 5:646a7e58989e | 57 | // at the end of the program, I reset the flags so it would be ready for the next loop. |
mehrnaz | 3:3d51f8870e91 | 58 | ///////////////////////////// |
christodoulos | 5:646a7e58989e | 59 | |
mehrnaz | 3:3d51f8870e91 | 60 | int bf=0; //FLAG for detecting base flow |
mehrnaz | 2:ef98576cd67b | 61 | int i=0; |
christodoulos | 5:646a7e58989e | 62 | float bfArray[4]; //sampling flow for finding the average base flow |
mehrnaz | 3:3d51f8870e91 | 63 | float sf=0; //sum of flow samples for calculating base flow |
mehrnaz | 3:3d51f8870e91 | 64 | float fv=0; //final value of base flow |
christodoulos | 5:646a7e58989e | 65 | |
mehrnaz | 3:3d51f8870e91 | 66 | int measurement_started=0; //FLAG for starting calculations after detecting breath |
christodoulos | 5:646a7e58989e | 67 | |
mehrnaz | 3:3d51f8870e91 | 68 | int solstart=0; //FLAG for starting calculations for detecting plateau |
mehrnaz | 3:3d51f8870e91 | 69 | int m=0; |
mehrnaz | 3:3d51f8870e91 | 70 | int myArray[9]; //sampling 9 values of CO2 |
mehrnaz | 3:3d51f8870e91 | 71 | unsigned int sum=0; //sum of 9 samples of CO2 |
mehrnaz | 3:3d51f8870e91 | 72 | int avg=0; //average of 9 samples of CO2 |
mehrnaz | 3:3d51f8870e91 | 73 | int difSum=0; //used for the Standard deviation algorithm |
mehrnaz | 3:3d51f8870e91 | 74 | long double var=0.0; //used for the Standard deviation algorithm |
mehrnaz | 3:3d51f8870e91 | 75 | float sigma=0.0; //final value for standar deviation |
mehrnaz | 3:3d51f8870e91 | 76 | int flags=0; //FLAG for keep taking samples from CO2 profile when it's too early to detect plateau |
christodoulos | 5:646a7e58989e | 77 | |
mehrnaz | 3:3d51f8870e91 | 78 | int solend=0; //FLAG for ending calculations for detecting plateau |
mehrnaz | 3:3d51f8870e91 | 79 | unsigned int sum2=0; //same as before; used for finding standard deviation |
mehrnaz | 2:ef98576cd67b | 80 | long double var2=0.0; |
mehrnaz | 2:ef98576cd67b | 81 | float sigma2=0.0; |
mehrnaz | 2:ef98576cd67b | 82 | int difSum2=0; |
mehrnaz | 3:3d51f8870e91 | 83 | int avg2=0; |
mehrnaz | 3:3d51f8870e91 | 84 | int flage=0; //FLAG for keep taking samples from CO2 profile when it's too early to finish plateau |
christodoulos | 5:646a7e58989e | 85 | |
mehrnaz | 2:ef98576cd67b | 86 | int fin=0; |
christodoulos | 6:f6faf142e5fc | 87 | wait(1); |
christodoulos | 6:f6faf142e5fc | 88 | sol=1;//sol off 1 |
christodoulos | 5:646a7e58989e | 89 | |
christodoulos | 5:646a7e58989e | 90 | while(1) { |
christodoulos | 6:f6faf142e5fc | 91 | |
christodoulos | 6:f6faf142e5fc | 92 | //led=0.4f; //an LED is fully turned on at the beginning, the brightness will be reduced when the plateau is detected. |
christodoulos | 5:646a7e58989e | 93 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 94 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 95 | wait(0.01); |
christodoulos | 5:646a7e58989e | 96 | if (bf==0) { //finding base flow before breath |
christodoulos | 5:646a7e58989e | 97 | for(i=0; i<4; i++) { |
christodoulos | 5:646a7e58989e | 98 | bfArray[i]=flow(); |
christodoulos | 5:646a7e58989e | 99 | sf+=bfArray[i]; |
christodoulos | 5:646a7e58989e | 100 | } |
christodoulos | 5:646a7e58989e | 101 | fv=sf/4; |
christodoulos | 6:f6faf142e5fc | 102 | //fv=fv+0.2; |
christodoulos | 6:f6faf142e5fc | 103 | fv=0.4; |
christodoulos | 5:646a7e58989e | 104 | //ttl.printf("set\n"); |
christodoulos | 5:646a7e58989e | 105 | bf=1; |
christodoulos | 5:646a7e58989e | 106 | } |
christodoulos | 5:646a7e58989e | 107 | |
christodoulos | 5:646a7e58989e | 108 | //Starts calculations when it detects breathing into the device: |
christodoulos | 5:646a7e58989e | 109 | |
christodoulos | 5:646a7e58989e | 110 | if ((flow()>fv) and (measurement_started ==0)) { |
christodoulos | 6:f6faf142e5fc | 111 | stream.start(); |
christodoulos | 5:646a7e58989e | 112 | measurement_started = 1; |
christodoulos | 5:646a7e58989e | 113 | } |
christodoulos | 5:646a7e58989e | 114 | |
christodoulos | 5:646a7e58989e | 115 | //Starts detecting plateau: |
christodoulos | 5:646a7e58989e | 116 | |
christodoulos | 5:646a7e58989e | 117 | if ((measurement_started == 1) and (solstart==0)) { |
mehrnaz | 3:3d51f8870e91 | 118 | |
christodoulos | 5:646a7e58989e | 119 | //Takes 9 samples of CO2: |
christodoulos | 5:646a7e58989e | 120 | //I have also included printing the values inside the loops so we don't loose any data during calculatins. |
christodoulos | 5:646a7e58989e | 121 | for(m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 122 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 123 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 124 | myArray[m]=carbon(); |
christodoulos | 5:646a7e58989e | 125 | wait(0.1); |
mehrnaz | 2:ef98576cd67b | 126 | } |
christodoulos | 5:646a7e58989e | 127 | while(flags==0) { |
christodoulos | 5:646a7e58989e | 128 | //While "flags" is enabled, keeps calculating the standard deviation. |
christodoulos | 5:646a7e58989e | 129 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 130 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 131 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 132 | sum+=myArray[m]; |
christodoulos | 5:646a7e58989e | 133 | wait(0.1); |
christodoulos | 5:646a7e58989e | 134 | |
christodoulos | 5:646a7e58989e | 135 | } |
christodoulos | 5:646a7e58989e | 136 | avg=sum/9; |
christodoulos | 5:646a7e58989e | 137 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 138 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 139 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 140 | difSum+=(myArray[m]-avg)*(myArray[m]-avg); //Find sum of difference between value X and mean |
christodoulos | 5:646a7e58989e | 141 | wait(0.1); |
christodoulos | 5:646a7e58989e | 142 | } |
christodoulos | 5:646a7e58989e | 143 | var=difSum/9; |
christodoulos | 5:646a7e58989e | 144 | sigma=sqrt(var); |
christodoulos | 5:646a7e58989e | 145 | if (sigma<0.02) { |
christodoulos | 5:646a7e58989e | 146 | |
christodoulos | 5:646a7e58989e | 147 | //if SD is less than 0.02 it means that it is too early to start the plateau |
christodoulos | 5:646a7e58989e | 148 | //So we shift all but the first sample and define the new set of arrays: |
christodoulos | 5:646a7e58989e | 149 | |
christodoulos | 5:646a7e58989e | 150 | for(int m=0; m<8; m++) { |
christodoulos | 5:646a7e58989e | 151 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 152 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 153 | myArray[m]=myArray[m+1]; //Shift all CO2 values to the left by 1 value |
christodoulos | 5:646a7e58989e | 154 | wait(0.1); |
christodoulos | 5:646a7e58989e | 155 | |
mehrnaz | 2:ef98576cd67b | 156 | } |
christodoulos | 5:646a7e58989e | 157 | myArray[8]=carbon(); //assign a new value for the 9th sample |
christodoulos | 5:646a7e58989e | 158 | } |
christodoulos | 5:646a7e58989e | 159 | //The new set of arrays are now generated and is sent back to be used for preveious SD calculations. |
christodoulos | 5:646a7e58989e | 160 | //If sigma for the new set is still small, a newer set will be generated and replaced |
christodoulos | 5:646a7e58989e | 161 | //Otherwise, it's accepted and will turn on the solenoid: |
christodoulos | 5:646a7e58989e | 162 | else { |
christodoulos | 6:f6faf142e5fc | 163 | sol=0; //Solenoid is ON 0 |
christodoulos | 6:f6faf142e5fc | 164 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), 100.00,s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 165 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), 0.00,s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor, CHANGED CO2 TO 0 |
christodoulos | 6:f6faf142e5fc | 166 | |
christodoulos | 6:f6faf142e5fc | 167 | //led=0.4f; //The brightness is reduced to half during the plateau |
christodoulos | 5:646a7e58989e | 168 | wait(0.1); |
christodoulos | 5:646a7e58989e | 169 | flags=1; //breakes the while loop |
christodoulos | 5:646a7e58989e | 170 | } |
mehrnaz | 2:ef98576cd67b | 171 | } |
christodoulos | 5:646a7e58989e | 172 | solend=1; //prepares the next section for finishing the plateau |
christodoulos | 5:646a7e58989e | 173 | solstart =1; |
christodoulos | 5:646a7e58989e | 174 | } |
christodoulos | 5:646a7e58989e | 175 | if ((measurement_started == 1) and (solend==1)) { |
christodoulos | 5:646a7e58989e | 176 | // same process happens for finishing the plateau: |
christodoulos | 5:646a7e58989e | 177 | |
christodoulos | 5:646a7e58989e | 178 | for(m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 179 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 180 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 181 | myArray[m]=carbon(); |
christodoulos | 5:646a7e58989e | 182 | wait(0.1); |
christodoulos | 5:646a7e58989e | 183 | } |
christodoulos | 5:646a7e58989e | 184 | while(flage==0) { |
christodoulos | 5:646a7e58989e | 185 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 186 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 187 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 188 | sum2+=myArray[m]; |
christodoulos | 5:646a7e58989e | 189 | wait(0.1); |
christodoulos | 5:646a7e58989e | 190 | } |
christodoulos | 5:646a7e58989e | 191 | avg2=sum2/9; |
christodoulos | 5:646a7e58989e | 192 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 193 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 194 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 195 | difSum2+=(myArray[m]-avg2)*(myArray[m]-avg2); |
christodoulos | 5:646a7e58989e | 196 | wait(0.1); |
christodoulos | 5:646a7e58989e | 197 | } |
christodoulos | 5:646a7e58989e | 198 | var2=difSum2/9; |
christodoulos | 5:646a7e58989e | 199 | sigma2=sqrt(var2); |
christodoulos | 5:646a7e58989e | 200 | if (sigma2<0.05) { |
christodoulos | 5:646a7e58989e | 201 | // here we defined the end threshold to be 0.05, it can be changed later based on experiment results |
christodoulos | 5:646a7e58989e | 202 | for(int m=0; m<8; m++) { |
christodoulos | 5:646a7e58989e | 203 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 204 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor, CHANGEC CO2 TO 0 |
christodoulos | 5:646a7e58989e | 205 | myArray[m]=myArray[m+1]; |
christodoulos | 5:646a7e58989e | 206 | wait(0.1); |
christodoulos | 5:646a7e58989e | 207 | |
mehrnaz | 2:ef98576cd67b | 208 | } |
christodoulos | 5:646a7e58989e | 209 | myArray[8]=carbon(); |
christodoulos | 5:646a7e58989e | 210 | } else { |
christodoulos | 6:f6faf142e5fc | 211 | sol=1; //Solenoid is OFF 1 |
christodoulos | 6:f6faf142e5fc | 212 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), 100.00,s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 213 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), 0.00,s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 214 | wait(0.1); |
christodoulos | 6:f6faf142e5fc | 215 | |
christodoulos | 5:646a7e58989e | 216 | flage=1; //breakes the loop |
christodoulos | 5:646a7e58989e | 217 | } |
christodoulos | 5:646a7e58989e | 218 | } |
christodoulos | 6:f6faf142e5fc | 219 | |
christodoulos | 6:f6faf142e5fc | 220 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 221 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor solend =0; //end of this section |
christodoulos | 6:f6faf142e5fc | 222 | //led=0.4f; //LED is back to full brightness |
christodoulos | 5:646a7e58989e | 223 | bf=0; //reset the detecting base flow flag |
christodoulos | 5:646a7e58989e | 224 | fin=1; //enables the next section flag |
christodoulos | 5:646a7e58989e | 225 | |
christodoulos | 5:646a7e58989e | 226 | |
christodoulos | 6:f6faf142e5fc | 227 | |
mehrnaz | 2:ef98576cd67b | 228 | } |
christodoulos | 5:646a7e58989e | 229 | |
christodoulos | 6:f6faf142e5fc | 230 | if(carbon()<2.00 && fin ==1) { |
christodoulos | 6:f6faf142e5fc | 231 | //User has to wait for the CO2 level to drop less than 1% before testing again. |
christodoulos | 6:f6faf142e5fc | 232 | //Once it is less than 1%, all the flags and parameters used in calculations are reset |
christodoulos | 6:f6faf142e5fc | 233 | |
christodoulos | 6:f6faf142e5fc | 234 | //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor |
christodoulos | 6:f6faf142e5fc | 235 | ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor solend =0; //end of this section |
christodoulos | 6:f6faf142e5fc | 236 | stream.reset(); |
christodoulos | 6:f6faf142e5fc | 237 | stream.stop(); |
christodoulos | 6:f6faf142e5fc | 238 | measurement_started =0; |
christodoulos | 6:f6faf142e5fc | 239 | solstart=0; |
christodoulos | 6:f6faf142e5fc | 240 | sum=0; |
christodoulos | 6:f6faf142e5fc | 241 | var=0.0; |
christodoulos | 6:f6faf142e5fc | 242 | sigma=0.0; |
christodoulos | 6:f6faf142e5fc | 243 | difSum=0; |
christodoulos | 6:f6faf142e5fc | 244 | sum2=0; |
christodoulos | 6:f6faf142e5fc | 245 | var2=0.0; |
christodoulos | 6:f6faf142e5fc | 246 | sigma2=0.0; |
christodoulos | 6:f6faf142e5fc | 247 | difSum2=0; |
christodoulos | 6:f6faf142e5fc | 248 | avg2=0; |
christodoulos | 6:f6faf142e5fc | 249 | avg=0; |
christodoulos | 6:f6faf142e5fc | 250 | flags=0; |
christodoulos | 6:f6faf142e5fc | 251 | flage=0; |
christodoulos | 6:f6faf142e5fc | 252 | fin=0; |
christodoulos | 6:f6faf142e5fc | 253 | } |
christodoulos | 5:646a7e58989e | 254 | |
mehrnaz | 2:ef98576cd67b | 255 | } |
mehrnaz | 2:ef98576cd67b | 256 | } |