SGP30 (used in POCBreath_V2_smd_commercial)
Dependencies: Adafruit_SGP30_mbed mbed
flow.h@2:ef98576cd67b, 2019-07-12 (annotated)
- Committer:
- mehrnaz
- Date:
- Fri Jul 12 15:58:11 2019 +0000
- Revision:
- 2:ef98576cd67b
- Child:
- 3:3d51f8870e91
handheld csv used for kst
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mehrnaz | 2:ef98576cd67b | 1 | #include "mbed.h" |
mehrnaz | 2:ef98576cd67b | 2 | |
mehrnaz | 2:ef98576cd67b | 3 | AnalogIn flowIn(PA_0); |
mehrnaz | 2:ef98576cd67b | 4 | Serial co2(PC_10,PC_11); //USED IN MAIN |
mehrnaz | 2:ef98576cd67b | 5 | //Serial ttl(A1,A0); |
mehrnaz | 2:ef98576cd67b | 6 | |
mehrnaz | 2:ef98576cd67b | 7 | float finalflow; |
mehrnaz | 2:ef98576cd67b | 8 | float flowVal1; |
mehrnaz | 2:ef98576cd67b | 9 | float flowVal2; |
mehrnaz | 2:ef98576cd67b | 10 | float P1; |
mehrnaz | 2:ef98576cd67b | 11 | int flag=0; |
mehrnaz | 2:ef98576cd67b | 12 | int o=0; |
mehrnaz | 2:ef98576cd67b | 13 | float bpArray[10]; |
mehrnaz | 2:ef98576cd67b | 14 | float fp;float sp; |
mehrnaz | 2:ef98576cd67b | 15 | float FPressure; |
mehrnaz | 2:ef98576cd67b | 16 | int value; |
mehrnaz | 2:ef98576cd67b | 17 | // |
mehrnaz | 2:ef98576cd67b | 18 | float flow() |
mehrnaz | 2:ef98576cd67b | 19 | { |
mehrnaz | 2:ef98576cd67b | 20 | while(1) |
mehrnaz | 2:ef98576cd67b | 21 | { |
mehrnaz | 2:ef98576cd67b | 22 | wait(0.01); |
mehrnaz | 2:ef98576cd67b | 23 | flowVal1=3.3*flowIn; //Logic level 3.3 |
mehrnaz | 2:ef98576cd67b | 24 | flowVal2 = 1.5*flowVal1; //5v |
mehrnaz | 2:ef98576cd67b | 25 | P1 =(125*flowVal2)-62.5; |
mehrnaz | 2:ef98576cd67b | 26 | if(flag==0) |
mehrnaz | 2:ef98576cd67b | 27 | { |
mehrnaz | 2:ef98576cd67b | 28 | finalflow=0; |
mehrnaz | 2:ef98576cd67b | 29 | bpArray[o]=P1; |
mehrnaz | 2:ef98576cd67b | 30 | sp+=bpArray[o]; |
mehrnaz | 2:ef98576cd67b | 31 | o=o+1; |
mehrnaz | 2:ef98576cd67b | 32 | if (o=9) |
mehrnaz | 2:ef98576cd67b | 33 | { |
mehrnaz | 2:ef98576cd67b | 34 | fp=sp/10; |
mehrnaz | 2:ef98576cd67b | 35 | flag=1; |
mehrnaz | 2:ef98576cd67b | 36 | } |
mehrnaz | 2:ef98576cd67b | 37 | } |
mehrnaz | 2:ef98576cd67b | 38 | if (flag==1) |
mehrnaz | 2:ef98576cd67b | 39 | { |
mehrnaz | 2:ef98576cd67b | 40 | FPressure=P1-fp; |
mehrnaz | 2:ef98576cd67b | 41 | finalflow=(0.24*sqrt(FPressure)); //flow in litter per min |
mehrnaz | 2:ef98576cd67b | 42 | //ttl.printf("Flow: %f\n",finalflow); |
mehrnaz | 2:ef98576cd67b | 43 | return finalflow; |
mehrnaz | 2:ef98576cd67b | 44 | } |
mehrnaz | 2:ef98576cd67b | 45 | } |
mehrnaz | 2:ef98576cd67b | 46 | } |
mehrnaz | 2:ef98576cd67b | 47 | |
mehrnaz | 2:ef98576cd67b | 48 | |
mehrnaz | 2:ef98576cd67b | 49 | float carbon() |
mehrnaz | 2:ef98576cd67b | 50 | { |
mehrnaz | 2:ef98576cd67b | 51 | bool allow = false; |
mehrnaz | 2:ef98576cd67b | 52 | char c; |
mehrnaz | 2:ef98576cd67b | 53 | char co2_measure[5]; |
mehrnaz | 2:ef98576cd67b | 54 | int count=0; |
mehrnaz | 2:ef98576cd67b | 55 | |
mehrnaz | 2:ef98576cd67b | 56 | while(1) |
mehrnaz | 2:ef98576cd67b | 57 | { |
mehrnaz | 2:ef98576cd67b | 58 | c = co2.getc(); |
mehrnaz | 2:ef98576cd67b | 59 | if(c=='Z') { |
mehrnaz | 2:ef98576cd67b | 60 | allow = true; |
mehrnaz | 2:ef98576cd67b | 61 | } |
mehrnaz | 2:ef98576cd67b | 62 | |
mehrnaz | 2:ef98576cd67b | 63 | if(allow) { |
mehrnaz | 2:ef98576cd67b | 64 | if(c>=48 && c<=57) { |
mehrnaz | 2:ef98576cd67b | 65 | co2_measure[count]=c; |
mehrnaz | 2:ef98576cd67b | 66 | count++; |
mehrnaz | 2:ef98576cd67b | 67 | } |
mehrnaz | 2:ef98576cd67b | 68 | |
mehrnaz | 2:ef98576cd67b | 69 | if(count>=6) { //NOT SURE IF 5 OR 6 |
mehrnaz | 2:ef98576cd67b | 70 | value = ((co2_measure[0]-'0')*100000+co2_measure[1]-'0')*10000+(co2_measure[2]-'0')*1000+(co2_measure[3]-'0')*100; |
mehrnaz | 2:ef98576cd67b | 71 | //ttl.printf("CO2: %d\n",value); |
mehrnaz | 2:ef98576cd67b | 72 | float CAR; |
mehrnaz | 2:ef98576cd67b | 73 | CAR=(float)value/10000; |
mehrnaz | 2:ef98576cd67b | 74 | count=0; |
mehrnaz | 2:ef98576cd67b | 75 | allow=false; |
mehrnaz | 2:ef98576cd67b | 76 | return CAR; |
mehrnaz | 2:ef98576cd67b | 77 | } |
mehrnaz | 2:ef98576cd67b | 78 | } |
mehrnaz | 2:ef98576cd67b | 79 | } |
mehrnaz | 2:ef98576cd67b | 80 | } |
mehrnaz | 2:ef98576cd67b | 81 |