POC Breath using SMD commercial sensors
Dependencies: iAQ_Core Adafruit_SGP30_mbed mbed BME680
main.cpp@5:646a7e58989e, 2020-01-23 (annotated)
- Committer:
- christodoulos
- Date:
- Thu Jan 23 15:24:41 2020 +0000
- Revision:
- 5:646a7e58989e
- Parent:
- 3:3d51f8870e91
- Child:
- 6:f6faf142e5fc
23rd Jan
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 | 5:646a7e58989e | 33 | ttl.printf("SN,myBoard\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 | 5:646a7e58989e | 37 | ttl.printf("---\r");//enter data mode |
christodoulos | 5:646a7e58989e | 38 | wait(0.5); |
christodoulos | 5:646a7e58989e | 39 | |
mehrnaz | 2:ef98576cd67b | 40 | flow(); //calling flow from flow.h |
mehrnaz | 2:ef98576cd67b | 41 | carbon(); //calling CO2 from flow.h |
mehrnaz | 3:3d51f8870e91 | 42 | s1(); //calling 8 channels from flow.h |
mehrnaz | 3:3d51f8870e91 | 43 | s2(); |
mehrnaz | 3:3d51f8870e91 | 44 | s3(); |
mehrnaz | 3:3d51f8870e91 | 45 | s4(); |
mehrnaz | 3:3d51f8870e91 | 46 | s5(); |
mehrnaz | 3:3d51f8870e91 | 47 | s6(); |
mehrnaz | 3:3d51f8870e91 | 48 | s7(); |
mehrnaz | 3:3d51f8870e91 | 49 | s8(); |
mehrnaz | 3:3d51f8870e91 | 50 | getTemp(); //calling Temperature from flow.h |
christodoulos | 5:646a7e58989e | 51 | |
mehrnaz | 3:3d51f8870e91 | 52 | ////////////////////////////// |
mehrnaz | 3:3d51f8870e91 | 53 | // I defined a flag for each section of specific functions, so by enabling the |
mehrnaz | 3:3d51f8870e91 | 54 | // flag the section starts and by disabling the flag it finishes the section. |
christodoulos | 5:646a7e58989e | 55 | // at the end of the program, I reset the flags so it would be ready for the next loop. |
mehrnaz | 3:3d51f8870e91 | 56 | ///////////////////////////// |
christodoulos | 5:646a7e58989e | 57 | |
mehrnaz | 3:3d51f8870e91 | 58 | int bf=0; //FLAG for detecting base flow |
mehrnaz | 2:ef98576cd67b | 59 | int i=0; |
christodoulos | 5:646a7e58989e | 60 | float bfArray[4]; //sampling flow for finding the average base flow |
mehrnaz | 3:3d51f8870e91 | 61 | float sf=0; //sum of flow samples for calculating base flow |
mehrnaz | 3:3d51f8870e91 | 62 | float fv=0; //final value of base flow |
christodoulos | 5:646a7e58989e | 63 | |
mehrnaz | 3:3d51f8870e91 | 64 | int measurement_started=0; //FLAG for starting calculations after detecting breath |
christodoulos | 5:646a7e58989e | 65 | |
mehrnaz | 3:3d51f8870e91 | 66 | int solstart=0; //FLAG for starting calculations for detecting plateau |
mehrnaz | 3:3d51f8870e91 | 67 | int m=0; |
mehrnaz | 3:3d51f8870e91 | 68 | int myArray[9]; //sampling 9 values of CO2 |
mehrnaz | 3:3d51f8870e91 | 69 | unsigned int sum=0; //sum of 9 samples of CO2 |
mehrnaz | 3:3d51f8870e91 | 70 | int avg=0; //average of 9 samples of CO2 |
mehrnaz | 3:3d51f8870e91 | 71 | int difSum=0; //used for the Standard deviation algorithm |
mehrnaz | 3:3d51f8870e91 | 72 | long double var=0.0; //used for the Standard deviation algorithm |
mehrnaz | 3:3d51f8870e91 | 73 | float sigma=0.0; //final value for standar deviation |
mehrnaz | 3:3d51f8870e91 | 74 | int flags=0; //FLAG for keep taking samples from CO2 profile when it's too early to detect plateau |
christodoulos | 5:646a7e58989e | 75 | |
mehrnaz | 3:3d51f8870e91 | 76 | int solend=0; //FLAG for ending calculations for detecting plateau |
mehrnaz | 3:3d51f8870e91 | 77 | unsigned int sum2=0; //same as before; used for finding standard deviation |
mehrnaz | 2:ef98576cd67b | 78 | long double var2=0.0; |
mehrnaz | 2:ef98576cd67b | 79 | float sigma2=0.0; |
mehrnaz | 2:ef98576cd67b | 80 | int difSum2=0; |
mehrnaz | 3:3d51f8870e91 | 81 | int avg2=0; |
mehrnaz | 3:3d51f8870e91 | 82 | int flage=0; //FLAG for keep taking samples from CO2 profile when it's too early to finish plateau |
christodoulos | 5:646a7e58989e | 83 | |
mehrnaz | 2:ef98576cd67b | 84 | int fin=0; |
christodoulos | 5:646a7e58989e | 85 | sol=1; |
christodoulos | 5:646a7e58989e | 86 | |
christodoulos | 5:646a7e58989e | 87 | while(1) { |
mehrnaz | 3:3d51f8870e91 | 88 | |
christodoulos | 5:646a7e58989e | 89 | led=0.2f; //an LED is fully turned on at the beginning, the brightness will be reduced when the plateau is detected. |
christodoulos | 5:646a7e58989e | 90 | //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 | 5:646a7e58989e | 91 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 92 | wait(0.01); |
christodoulos | 5:646a7e58989e | 93 | if (bf==0) { //finding base flow before breath |
christodoulos | 5:646a7e58989e | 94 | for(i=0; i<4; i++) { |
christodoulos | 5:646a7e58989e | 95 | bfArray[i]=flow(); |
christodoulos | 5:646a7e58989e | 96 | sf+=bfArray[i]; |
christodoulos | 5:646a7e58989e | 97 | } |
christodoulos | 5:646a7e58989e | 98 | fv=sf/4; |
christodoulos | 5:646a7e58989e | 99 | fv=fv+0.5; |
christodoulos | 5:646a7e58989e | 100 | //ttl.printf("set\n"); |
christodoulos | 5:646a7e58989e | 101 | bf=1; |
christodoulos | 5:646a7e58989e | 102 | } |
christodoulos | 5:646a7e58989e | 103 | |
christodoulos | 5:646a7e58989e | 104 | //Starts calculations when it detects breathing into the device: |
christodoulos | 5:646a7e58989e | 105 | |
christodoulos | 5:646a7e58989e | 106 | if ((flow()>fv) and (measurement_started ==0)) { |
christodoulos | 5:646a7e58989e | 107 | stream.start(); // PROGRAM COMES HERES DIRECTLY, CHCK WHY FLOW GOES ABOVE FV |
christodoulos | 5:646a7e58989e | 108 | measurement_started = 1; |
christodoulos | 5:646a7e58989e | 109 | } |
christodoulos | 5:646a7e58989e | 110 | |
christodoulos | 5:646a7e58989e | 111 | //Starts detecting plateau: |
christodoulos | 5:646a7e58989e | 112 | |
christodoulos | 5:646a7e58989e | 113 | if ((measurement_started == 1) and (solstart==0)) { |
mehrnaz | 3:3d51f8870e91 | 114 | |
christodoulos | 5:646a7e58989e | 115 | //Takes 9 samples of CO2: |
christodoulos | 5:646a7e58989e | 116 | //I have also included printing the values inside the loops so we don't loose any data during calculatins. |
christodoulos | 5:646a7e58989e | 117 | for(m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 118 | //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 | 5:646a7e58989e | 119 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 120 | myArray[m]=carbon(); |
christodoulos | 5:646a7e58989e | 121 | wait(0.1); |
mehrnaz | 2:ef98576cd67b | 122 | } |
christodoulos | 5:646a7e58989e | 123 | while(flags==0) { |
christodoulos | 5:646a7e58989e | 124 | //While "flags" is enabled, keeps calculating the standard deviation. |
christodoulos | 5:646a7e58989e | 125 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 126 | //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 | 5:646a7e58989e | 127 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 128 | sum+=myArray[m]; |
christodoulos | 5:646a7e58989e | 129 | wait(0.1); |
christodoulos | 5:646a7e58989e | 130 | |
christodoulos | 5:646a7e58989e | 131 | } |
christodoulos | 5:646a7e58989e | 132 | avg=sum/9; |
christodoulos | 5:646a7e58989e | 133 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 134 | //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 | 5:646a7e58989e | 135 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 136 | difSum+=(myArray[m]-avg)*(myArray[m]-avg); //Find sum of difference between value X and mean |
christodoulos | 5:646a7e58989e | 137 | wait(0.1); |
christodoulos | 5:646a7e58989e | 138 | } |
christodoulos | 5:646a7e58989e | 139 | var=difSum/9; |
christodoulos | 5:646a7e58989e | 140 | sigma=sqrt(var); |
christodoulos | 5:646a7e58989e | 141 | if (sigma<0.02) { |
christodoulos | 5:646a7e58989e | 142 | |
christodoulos | 5:646a7e58989e | 143 | //if SD is less than 0.02 it means that it is too early to start the plateau |
christodoulos | 5:646a7e58989e | 144 | //So we shift all but the first sample and define the new set of arrays: |
christodoulos | 5:646a7e58989e | 145 | |
christodoulos | 5:646a7e58989e | 146 | for(int m=0; m<8; m++) { |
christodoulos | 5:646a7e58989e | 147 | //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 | 5:646a7e58989e | 148 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 149 | myArray[m]=myArray[m+1]; //Shift all CO2 values to the left by 1 value |
christodoulos | 5:646a7e58989e | 150 | wait(0.1); |
christodoulos | 5:646a7e58989e | 151 | |
mehrnaz | 2:ef98576cd67b | 152 | } |
christodoulos | 5:646a7e58989e | 153 | myArray[8]=carbon(); //assign a new value for the 9th sample |
christodoulos | 5:646a7e58989e | 154 | } |
christodoulos | 5:646a7e58989e | 155 | //The new set of arrays are now generated and is sent back to be used for preveious SD calculations. |
christodoulos | 5:646a7e58989e | 156 | //If sigma for the new set is still small, a newer set will be generated and replaced |
christodoulos | 5:646a7e58989e | 157 | //Otherwise, it's accepted and will turn on the solenoid: |
christodoulos | 5:646a7e58989e | 158 | else { |
christodoulos | 5:646a7e58989e | 159 | //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 | 5:646a7e58989e | 160 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor, CHANGED CO2 TO 0 |
christodoulos | 5:646a7e58989e | 161 | sol=0; //Solenoid is ON |
christodoulos | 5:646a7e58989e | 162 | //led=0.8f; //The brightness is reduced to half during the plateau |
christodoulos | 5:646a7e58989e | 163 | wait(0.1); |
christodoulos | 5:646a7e58989e | 164 | flags=1; //breakes the while loop |
christodoulos | 5:646a7e58989e | 165 | } |
mehrnaz | 2:ef98576cd67b | 166 | } |
christodoulos | 5:646a7e58989e | 167 | solend=1; //prepares the next section for finishing the plateau |
christodoulos | 5:646a7e58989e | 168 | solstart =1; |
christodoulos | 5:646a7e58989e | 169 | } |
christodoulos | 5:646a7e58989e | 170 | if ((measurement_started == 1) and (solend==1)) { |
christodoulos | 5:646a7e58989e | 171 | // same process happens for finishing the plateau: |
christodoulos | 5:646a7e58989e | 172 | |
christodoulos | 5:646a7e58989e | 173 | for(m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 174 | //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 | 5:646a7e58989e | 175 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 176 | myArray[m]=carbon(); |
christodoulos | 5:646a7e58989e | 177 | wait(0.1); |
christodoulos | 5:646a7e58989e | 178 | } |
christodoulos | 5:646a7e58989e | 179 | while(flage==0) { |
christodoulos | 5:646a7e58989e | 180 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 181 | //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 | 5:646a7e58989e | 182 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 183 | sum2+=myArray[m]; |
christodoulos | 5:646a7e58989e | 184 | wait(0.1); |
christodoulos | 5:646a7e58989e | 185 | } |
christodoulos | 5:646a7e58989e | 186 | avg2=sum2/9; |
christodoulos | 5:646a7e58989e | 187 | for(int m=0; m<9; m++) { |
christodoulos | 5:646a7e58989e | 188 | //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 | 5:646a7e58989e | 189 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 190 | difSum2+=(myArray[m]-avg2)*(myArray[m]-avg2); |
christodoulos | 5:646a7e58989e | 191 | wait(0.1); |
christodoulos | 5:646a7e58989e | 192 | } |
christodoulos | 5:646a7e58989e | 193 | var2=difSum2/9; |
christodoulos | 5:646a7e58989e | 194 | sigma2=sqrt(var2); |
christodoulos | 5:646a7e58989e | 195 | if (sigma2<0.05) { |
christodoulos | 5:646a7e58989e | 196 | // here we defined the end threshold to be 0.05, it can be changed later based on experiment results |
christodoulos | 5:646a7e58989e | 197 | for(int m=0; m<8; m++) { |
christodoulos | 5:646a7e58989e | 198 | //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 | 5:646a7e58989e | 199 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor, CHANGEC CO2 TO 0 |
christodoulos | 5:646a7e58989e | 200 | myArray[m]=myArray[m+1]; |
christodoulos | 5:646a7e58989e | 201 | wait(0.1); |
christodoulos | 5:646a7e58989e | 202 | |
mehrnaz | 2:ef98576cd67b | 203 | } |
christodoulos | 5:646a7e58989e | 204 | myArray[8]=carbon(); |
christodoulos | 5:646a7e58989e | 205 | } else { |
christodoulos | 5:646a7e58989e | 206 | //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 | 5:646a7e58989e | 207 | 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(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor |
christodoulos | 5:646a7e58989e | 208 | wait(0.1); |
christodoulos | 5:646a7e58989e | 209 | sol=1; //Solenoid is OFF |
christodoulos | 5:646a7e58989e | 210 | flage=1; //breakes the loop |
christodoulos | 5:646a7e58989e | 211 | } |
christodoulos | 5:646a7e58989e | 212 | } |
christodoulos | 5:646a7e58989e | 213 | solend =0; //end of this section |
christodoulos | 5:646a7e58989e | 214 | led=0.20f; //LED is back to full brightness |
christodoulos | 5:646a7e58989e | 215 | bf=0; //reset the detecting base flow flag |
christodoulos | 5:646a7e58989e | 216 | fin=1; //enables the next section flag |
christodoulos | 5:646a7e58989e | 217 | |
christodoulos | 5:646a7e58989e | 218 | |
mehrnaz | 2:ef98576cd67b | 219 | } |
christodoulos | 5:646a7e58989e | 220 | |
christodoulos | 5:646a7e58989e | 221 | if((carbon()<1.0) && (fin ==1)) { //CHECK IF CO2 SHOULD BE 1 OR 0.75 |
christodoulos | 5:646a7e58989e | 222 | //User has to wait for the CO2 level to drop less than 1% before testing again. |
christodoulos | 5:646a7e58989e | 223 | //Once it is less than 1%, all the flags and parameters used in calculations are reset |
christodoulos | 5:646a7e58989e | 224 | stream.stop(); |
christodoulos | 5:646a7e58989e | 225 | stream.reset(); |
christodoulos | 5:646a7e58989e | 226 | measurement_started =0; |
christodoulos | 5:646a7e58989e | 227 | solstart=0; |
christodoulos | 5:646a7e58989e | 228 | sum=0; |
christodoulos | 5:646a7e58989e | 229 | var=0.0; |
christodoulos | 5:646a7e58989e | 230 | sigma=0.0; |
christodoulos | 5:646a7e58989e | 231 | difSum=0; |
christodoulos | 5:646a7e58989e | 232 | sum2=0; |
christodoulos | 5:646a7e58989e | 233 | var2=0.0; |
christodoulos | 5:646a7e58989e | 234 | sigma2=0.0; |
christodoulos | 5:646a7e58989e | 235 | difSum2=0; |
christodoulos | 5:646a7e58989e | 236 | avg2=0; |
christodoulos | 5:646a7e58989e | 237 | avg=0; |
christodoulos | 5:646a7e58989e | 238 | flags=0; |
christodoulos | 5:646a7e58989e | 239 | flage=0; |
christodoulos | 5:646a7e58989e | 240 | fin=0; |
christodoulos | 5:646a7e58989e | 241 | } |
christodoulos | 5:646a7e58989e | 242 | |
mehrnaz | 2:ef98576cd67b | 243 | } |
mehrnaz | 2:ef98576cd67b | 244 | } |