Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 3:c5ab85ed8c39, committed 2019-06-04
- Comitter:
- mehrnaz
- Date:
- Tue Jun 04 14:45:38 2019 +0000
- Parent:
- 2:af7522079ec4
- Commit message:
- HandHeld
Changed in this revision
| flow.h | Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/flow.h Tue Apr 16 09:19:53 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-#include "mbed.h"
-
-AnalogIn flowIn(A0);
-
-float flowVal;
-
-float flow(){
- while(1){
- flowVal=3.3*flowIn; //Logic level 3.3
- return flowVal;
- }
-}
\ No newline at end of file
--- a/main.cpp Tue Apr 16 09:19:53 2019 +0000
+++ b/main.cpp Tue Jun 04 14:45:38 2019 +0000
@@ -3,7 +3,7 @@
#include "co2.h"
#include "time.h"
-//Serial ble(A4,A5);
+Serial ble(A4,A5);
AnalogIn flowIn(A3);
AnalogIn temp(A2);
Timer t;
@@ -37,7 +37,7 @@
while(1) {
flowVal=(sqrt(((flowIn*3.3)*1.5)*125-62.5))*0.24; //Logic level 3.3
-// printf("Flow: %f", flowVal);
+// ble.printf("Flow: %f", flowVal);
}
}
@@ -55,7 +55,7 @@
float r2 = (3.3*rRef/v)-rRef; //Convert voltage into thermistor resistance
float t2 = (B*t1)/(B-t1*log(r1/r2)); //Convert thermistor resistance into temperature in Kelvin (log means natural logarithm ln)
t2Cel = t2-273; //Convert temperature from Kelvin to Celcius
-// printf("Temp: %f\n", t2Cel);
+// ble.printf("Temp: %f\n", t2Cel);
}
}
@@ -63,7 +63,7 @@
int main()
{
- // ble.baud(9600);
+ ble.baud(9600);
float mc,ac;
int k,u,b;
int flagg=0;
@@ -79,6 +79,7 @@
float co2Array[80];
float flowArray[40];
+ float bfArray[4];
long double var=0.0;
float sigma=0.0;
float sum=0;
@@ -104,28 +105,44 @@
//int measurement_started = 0;
int maxflag=0;
float fv=0;
-
+ int bf=0;
+ float sf=0;
int i = 0;
int j=0;
+ int o=0;
+ int ready=0;
///*******
while(1) {
- //printf(" CO2: %d, Flow: %f, \n", carbon(), flowVal ); //COOL TERM
+ // ble.printf(" CO2: %d, Flow: %f, \n", carbon(), flowVal ); //COOL TERM
+ if (bf==0)
+ {
+ for(o=0; o<4; o++)
+ {
+ bfArray[o]=flowVal;
+ sf+=bfArray[j];
+ }
+ fv=sf/4;
+ // ble.printf("first fv: %f \n", fv);
+ fv=fv+0.2;
+ // ble.printf("sec fv: %f \n", fv);
+ bf=1;
+ }
- //for(j=0; j<10; j++)
-// {
-// flowArray[j]=flowVal;
-// }
-
-
- if ((flowVal>0.8) and (measurement_started ==0)) {
+ if((carbon()<10000) and (ready ==1))
+ {
+ ble.printf("Now you can breathe into device. \n");
+ ready=0;
+ }
+
+ if ((flowVal>fv) and (measurement_started ==0)) {
// time(&start_t);
measurement_started = 1;
- printf("Balloon is blowing \n");
- printf("Calculating... \n");
+ ble.printf("Balloon is blowing \n");
+ ble.printf("Calculating... \n");
}
@@ -135,7 +152,7 @@
for(j=0; j<40; j++) {
flowArray[j]=flowVal;
co2Array[j]=carbon();
- //printf("co2array[%d] %f \n",k,co2Array[k]);
+ // ble.printf("co2array[%d] %f \n",k,co2Array[k]);
@@ -146,7 +163,7 @@
for(j=40; j<80; j++) {
co2Array[j]=carbon();
- //printf("co2array[%d] %f \n",k,co2Array[k]);
+ // ble.printf("co2array[%d] %f \n",k,co2Array[k]);
wait(0.1);
}
@@ -174,14 +191,14 @@
if (flowArray[j] > maximum) {
maximum = flowArray[j];
- // printf("Max: %f",maximum);
+ // ble.printf("Max: %f",maximum);
}
}
maxflag=0;
measurement_started =1;
}
- if((flowVal<0.8) and (measurement_started == 1)) {
+ if((flowVal<fv) and (measurement_started == 1)) {
// time(&end_t);
//T = difftime(end_t, start_t);
@@ -193,45 +210,31 @@
//cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
// T=cpu_time_used;
- // printf("t=%f \n", T);
+ // ble.printf("t=%f \n", T);
// T=0;
- printf("********* \n");
- printf("Your breath results: \n");
+ ble.printf("********* \n");
+ ble.printf("Your breath results: \n");
- printf("Maximum Flow: %3.2f Litres/Second \n",maximum);
+ ble.printf("Maximum Flow: %3.2f Litres/Second \n",maximum);
for(j=0; j<39; j++) {
flowsum[j]=((flowArray[j]+flowArray[j+1])*0.1)/2;
- //printf("flowsum %f \n",flowsum[j]);
+ // ble.printf("flowsum %f \n",flowsum[j]);
finalsum+=flowsum[j];
}
- printf("Lung Capacity: %3.2f Litres \n",finalsum);
-
- if (finalsum<0.9) {
- printf("Breath Score: 1 \n");
- }
- if((finalsum>1) and (finalsum<1.9)) {
- printf("Breath Score: 2 \n");
- }
- if((finalsum>2) and (finalsum<2.9)) {
- printf("Breath Score: 3 \n");
- }
- if((finalsum>3) and (finalsum<3.9)) {
- printf("Breath Score: 4 \n");
- }
- if((finalsum>4) and (finalsum<5)) {
- printf("Breath Score: 5 \n");
- }
- finalsum=0;
+ ble.printf("Lung Capacity: %3.2f Litres \n",finalsum);
+
+
+ fv=0;
cflag=1;
}
if(cflag==1) {
for(j=0; j<80; j++) {
- //printf("co2[%d]: %f \n",j,co2Array[j]);
+ // ble.printf("co2[%d]: %f \n",j,co2Array[j]);
sum+=co2Array[j];
}
maximumco2 = co2Array[0];
@@ -241,22 +244,44 @@
if (co2Array[j] > maximumco2) {
maximumco2 = co2Array[j];
- // printf("Max: %f",maximum);
+ // ble.printf("Max: %f",maximum);
}
}
mc=maximumco2/10000;
- printf("Maximum CO2: %3.2f percent \n",mc);
- // printf("co2 sum: %f \n",sum);
+ ble.printf("Maximum CO2: %3.2f percent \n",mc);
+ // ble.printf("co2 sum: %f \n",sum);
avg=sum/80;
ac=avg/10000;
- printf("CO2 Average: %3.2f percent \n", ac);
- printf("********* \n");
- printf("Nice Job! You can try again. \n");
+ ble.printf("CO2 Average: %3.2f percent \n", ac);
+ ble.printf("********* \n");
+ if (finalsum<0.9) {
+ ble.printf("Breath Score: 1 \n");
+ }
+ if((finalsum>1) and (finalsum<1.9)) {
+ ble.printf("Breath Score: 2 \n");
+ }
+ if((finalsum>2) and (finalsum<2.9)) {
+ ble.printf("Breath Score: 3 \n");
+ }
+ if((finalsum>3) and (finalsum<3.9)) {
+ ble.printf("Breath Score: 4 \n");
+ }
+ if((finalsum>4) and (finalsum<5)) {
+ ble.printf("Breath Score: 5 \n");
+ }
+ ble.printf("********* \n");
+ ble.printf("Nice Job! Please wait for the next try. \n");
+
+
+
+ finalsum=0;
+ ready=1;
ac=0;
mc=0;
sum=0;
cflag=0;
+ bf=0;