SGP30 (used in POCBreath_V2_smd_commercial)
Dependencies: Adafruit_SGP30_mbed mbed
Diff: flow.h
- Revision:
- 2:ef98576cd67b
- Child:
- 3:3d51f8870e91
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flow.h Fri Jul 12 15:58:11 2019 +0000 @@ -0,0 +1,81 @@ +#include "mbed.h" + +AnalogIn flowIn(PA_0); +Serial co2(PC_10,PC_11); //USED IN MAIN +//Serial ttl(A1,A0); + +float finalflow; +float flowVal1; +float flowVal2; +float P1; +int flag=0; +int o=0; +float bpArray[10]; +float fp;float sp; +float FPressure; +int value; +// +float flow() +{ + while(1) + { + wait(0.01); + flowVal1=3.3*flowIn; //Logic level 3.3 + flowVal2 = 1.5*flowVal1; //5v + P1 =(125*flowVal2)-62.5; + if(flag==0) + { + finalflow=0; + bpArray[o]=P1; + sp+=bpArray[o]; + o=o+1; + if (o=9) + { + fp=sp/10; + flag=1; + } + } + if (flag==1) + { + FPressure=P1-fp; + finalflow=(0.24*sqrt(FPressure)); //flow in litter per min + //ttl.printf("Flow: %f\n",finalflow); + return finalflow; + } + } +} + + +float carbon() +{ + bool allow = false; + char c; + char co2_measure[5]; + int count=0; + + while(1) + { + c = co2.getc(); + if(c=='Z') { + allow = true; + } + + if(allow) { + if(c>=48 && c<=57) { + co2_measure[count]=c; + count++; + } + + if(count>=6) { //NOT SURE IF 5 OR 6 + value = ((co2_measure[0]-'0')*100000+co2_measure[1]-'0')*10000+(co2_measure[2]-'0')*1000+(co2_measure[3]-'0')*100; + //ttl.printf("CO2: %d\n",value); + float CAR; + CAR=(float)value/10000; + count=0; + allow=false; + return CAR; + } + } + } +} +