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 1:af991edb6dc1, committed 2019-07-04
- Comitter:
- christodoulos
- Date:
- Thu Jul 04 09:09:54 2019 +0000
- Parent:
- 0:958e045ea7d1
- Commit message:
- Handheld with solenoid
Changed in this revision
--- a/co2.h Fri Mar 22 10:31:21 2019 +0000
+++ b/co2.h Thu Jul 04 09:09:54 2019 +0000
@@ -1,6 +1,6 @@
#include "mbed.h"
-Serial co2(D1,D0);
+Serial co2(D1,D0); //USED IN MAIN
int value;
@@ -24,8 +24,8 @@
count++;
}
- if(count>=5) {
- value = ((co2_measure[1]-'0')*100000+co2_measure[2]-'0')*10000+(co2_measure[3]-'0')*1000+(co2_measure[4]-'0')*100;
+ 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;
count=0;
allow=false;
return value;
--- a/flow.h Fri Mar 22 10:31:21 2019 +0000 +++ b/flow.h Thu Jul 04 09:09:54 2019 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" -AnalogIn flowIn(A0); +AnalogIn flowIn(A3); float flowVal;
--- a/main.cpp Fri Mar 22 10:31:21 2019 +0000
+++ b/main.cpp Thu Jul 04 09:09:54 2019 +0000
@@ -1,7 +1,7 @@
#include "mbed.h"
#include "co2.h"
-AnalogIn flowIn(A0);
+AnalogIn flowIn(A3);
AnalogIn temp(A2);
Timer t;
Thread co2Thread;
@@ -53,66 +53,66 @@
carbon();
t.start();
- while(1){
- printf("CO2: %d, Flow: %f, Temp: %f\n", carbon(), flowVal, t2Cel); //COOL TERM
-// printf("$d %f %f;", carbon(), flowVal, t2Cel); //Serial plotter
+// while(1){
+// printf("CO2: %d, Flow: %f, Temp: %f\n", carbon(), flowVal, t2Cel); //COOL TERM
+//// printf("$d %f %f;", carbon(), flowVal, t2Cel); //Serial plotter
+// }
+
+ //SOLENOID PART//
+ while(1){
+ int array[9]={0,0,0,0,0,0,0,0,0};
+ for(int i=0;i<=8;i++){
+ array[i]=carbon();
+ }
+ //printf("%d %d %d %d %d %d %d %d %d\n", array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8]);
+
+ }
+
+ for(int i=0;i<9;i++){ //Get first 9 carbon values
+ myArray[i]=carbon();
+ printf("%d ", myArray[i]);
+ }
+
+ printf("\n");
+
+ while(flag!=true){
+ for(int i=0;i<9;i++){
+ sum+=myArray[i]; //Find sum
}
+ avg=sum/9;//find average
-// while(1){
-// int array[9]={0,0,0,0,0,0,0,0,0};
-// for(int i=0;i<=8;i++){
-// array[i]=carbon();
-// }
-// printf("%d %d %d %d %d %d %d %d %d\n", array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8]);
-//
-// }
-//
-// for(int i=0;i<9;i++){ //Get first 9 carbon values
-// myArray[i]=carbon();
-// printf("%d ", myArray[i]);
-// }
-//
-// printf("\n");
-//
-// while(flag!=true){
-// for(int i=0;i<9;i++){
-// sum+=myArray[i]; //Find sum
-// }
-//
-// avg=sum/9;//find average
-//
-// printf("Avg: %d\n", avg);
-//
-// for(int i=0;i<9;i++){
-// difSum+=(myArray[i]-avg)*(myArray[i]-avg); //Find sum of difference between value X and mean
-// }
-//
-// var=difSum/9;
-// sigma=sqrt(var);
-//
-// printf("Standard dev: %f\n", sigma);
-//
-// if(sigma>=0.5){ //Check against carbon plateau, if sd greater than plateau startPoint
-// for(int x=0;x<8;x++){
-// myArray[x]=myArray[x+1]; //Shift all carbon to left by 1
-// printf("%d ", myArray[x]);
-// }
-//
-// myArray[8]=carbon(); // get new carbon value in last array slot
-// printf("%d\n", myArray[8]);
-//
-// sum=0; //Reset variables
-// sqSum=0;
-// var=0;
-// sigma=0;
-// avg=0;
-// difSum=0;
-//
-// }else{
-// printf("TURN ON SOLENOID\n"); //Turn on second sensor
-// flag=true; //Terminate loop because sd is at plateau startPoint
-// }
-// }
+ printf("Avg: %d\n", avg);
+
+ for(int i=0;i<9;i++){
+ difSum+=(myArray[i]-avg)*(myArray[i]-avg); //Find sum of difference between value X and mean
+ }
+
+ var=difSum/9;
+ sigma=sqrt(var);
+
+ printf("Standard dev: %f\n", sigma);
+
+ if(sigma>=0.5){ //Check against carbon plateau, if sd greater than plateau startPoint
+ for(int x=0;x<8;x++){
+ myArray[x]=myArray[x+1]; //Shift all carbon to left by 1
+ printf("%d ", myArray[x]);
+ }
+
+ myArray[8]=carbon(); // get new carbon value in last array slot
+ printf("%d\n", myArray[8]);
+
+ sum=0; //Reset variables
+ sqSum=0;
+ var=0;
+ sigma=0;
+ avg=0;
+ difSum=0;
+
+ }else{
+ printf("TURN ON SOLENOID\n"); //Turn on second sensor
+ flag=true; //Terminate loop because sd is at plateau startPoint
+ }
+ }
}