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: BMP180 N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 21:d76880ca7499
- Parent:
- 20:ec528f0e63c5
- Child:
- 22:f3dfa2a4e79a
--- a/main.cpp Sun May 03 14:35:37 2015 +0000
+++ b/main.cpp Tue May 05 12:00:48 2015 +0000
@@ -46,19 +46,20 @@
float temperature;
float pressure;
-int averageTemperature ;
-int averagePressure ;
-int minTemperature ;
-int maxTemperature ;
-int minPressure;
-int maxPressure;
+float averageTemperature ;
+float averagePressure ;
+float minTemperature ;
+float maxTemperature ;
+float minPressure;
+float maxPressure;
-float arrayT[83] ; // An array to store the values of temperature to draw graphs
-float arrayP[83] ; // An array to store the values of pressure to draw graphs
-
+float arrayT[83] ; // An array to store the values of temperature to calculate the average min max values
+float arrayP[83] ; // An array to store the values of pressure to calculate the average min max values
+float arrayTG[83] ; // An array to store the values of temperature to draw the graphs
+float arrayPG[83] ;
char rxString[16]; //buffer to store recieved string from serial
@@ -81,14 +82,14 @@
//arrays used to store data to the local file
-char timeSent[100];
-char dateSent[100];
-char temperatureSent[100];
-char pressureSent[100];
-char temperatureRecieved[100];
-char pressureRecieved[100];
-char timeRecieved[100];
-char dateRecieved[100];
+char timeSent[420+84];
+char dateSent[672+84];
+char temperatureSent[252+84];
+char pressureSent[504+84];
+char temperatureRecieved[252+84];
+char pressureRecieved[504+84];
+char timeRecieved[420+84];
+char dateRecieved[672+84];
//cahrs used to split arrays into indexes
@@ -293,13 +294,13 @@
// serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
- if (unitFlag==1 || unitFlag==2 ) {
+ if (unitFlag==1 || unitFlag==2 ) { //c
temperature = measurement.temperature;
int length = sprintf(bufferT,"%0.1f",temperature); // print formatted data to buffer
// it is important the format specifier ensures the length will fit in the buffer
}
- if (unitFlag==3 || unitFlag==4 ) {
+ if (unitFlag==3 || unitFlag==4 ) {//f
temperature =( measurement.temperature*(9/5))+32;
int length = sprintf(bufferT,"%0.1f",temperature); // print formatted data to buffer
// it is important the format specifier ensures the length will fit in the buffer
@@ -308,12 +309,12 @@
- if (unitFlag==1 || unitFlag==3 ) {
+ if (unitFlag==1 || unitFlag==3 ) {//mb
pressure = measurement.pressure; // same idea with float
int length = sprintf(bufferP,"%.2f",pressure); // print formatted data to buffer
// it is important the format specifier ensures the length will fit in the buffer
}
- if (unitFlag==2 || unitFlag==4 ) {
+ if (unitFlag==2 || unitFlag==4 ) {//atm
pressure = measurement.pressure*0.0009869; // same idea with floats
int length = sprintf(bufferP,"%.2f",pressure); // print formatted data to buffer
// it is important the format specifier ensures the length will fit in the buffer
@@ -447,7 +448,7 @@
minPressure = arrayP[0];
maxTemperature = arrayT[0];
maxPressure = arrayP[0];
- yellowLED = 1;
+ greenLED = 1;
readData();
dataLoggerFlag=0;
@@ -500,8 +501,9 @@
pch2 = strtok (NULL, ",");
p++;
}
+
+ p=0;
pch3 = strtok (pressureRecieved,",");
- p=0;
while (pch3 != NULL) {
serial.printf (" splitted pressure= %s\n",pch3);
arrayP[p]=atof(pch3);
@@ -511,9 +513,30 @@
// calculate the average value of the arrays and save them to an integer
- for (k = 0 ; k<=i ; k++) { // loops through the arrays
+ for (k = 0 ; k<p ; k++) { // loops through the arrays
printf("arrayT = %lf\n",arrayT[k]);
printf("arrayP = %lf\n",arrayP[k]);
+
+
+ if (unitFlag==1 || unitFlag==2 ) { //c
+ arrayTG[k]=(arrayT[k]/60);
+ }
+ if (unitFlag==3 || unitFlag==4 ) {//f
+ arrayTG[k]=(arrayT[k]/140);
+ }
+
+
+
+
+ if (unitFlag==1 || unitFlag==3 ) {//mb
+ arrayPG[k]=(arrayP[k]/1500);
+ }
+ if (unitFlag==2 || unitFlag==4 ) {//atm
+ arrayPG[k]=(arrayP[k]/2);
+ }
+
+
+
sumTemperature += arrayT[k]; // calculates the sum of the stored values
averageTemperature = sumTemperature/(k+1) ; //calculates the average value
@@ -542,7 +565,7 @@
i=0;
}
}
- yellowLED = 0;
+ greenLED = 0;
}
@@ -560,6 +583,7 @@
loggerData();
+
if (button4Flag) {
button4Flag = 0 ;
swipe ++;
@@ -574,30 +598,30 @@
switch (swipe) {
case 1: {
int display1 = sprintf (buffer1, "Temperature");
- int display2 = sprintf (buffer2, "Min = %d", minTemperature);
- int display3 = sprintf (buffer3, "Max = %d", maxTemperature);
- int display4 = sprintf (buffer4, "Avg = %d", averageTemperature);
+ int display2 = sprintf (buffer2, "Min = %0.2f", minTemperature);
+ int display3 = sprintf (buffer3, "Max = %0.2f", maxTemperature);
+ int display4 = sprintf (buffer4, "Avg = %0.2f", averageTemperature);
display();
break;
}
case 2 : {
lcd.clear();
lcd.printString(" Temperature",0,0);
- lcd.plotArray(arrayT);
+ lcd.plotArray(arrayTG);
break;
}
case 3 : {
int display11 = sprintf (buffer1, "Pressure");
- int display22 = sprintf (buffer2, "Min = %d", minPressure);
- int display33 = sprintf (buffer3, "Max = %d", maxPressure);
- int display44 = sprintf (buffer4, "Avg = %d", averagePressure);
+ int display22 = sprintf (buffer2, "Min = %0.2f", minPressure);
+ int display33 = sprintf (buffer3, "Max = %0.2f", maxPressure);
+ int display44 = sprintf (buffer4, "Avg = %0.2f", averagePressure);
display();
break;
}
case 4 : {
lcd.clear();
lcd.printString(" Pressure",0,0);
- lcd.plotArray(arrayP);
+ lcd.plotArray(arrayPG);
break;
}
default :
@@ -856,12 +880,6 @@
wakeUp();
updateTime();
loggerData();
- stateminus1=fsmC[state].nextState[0];
- stateminus2=fsmC[stateminus1].nextState[0];
- stateplus1=fsmC[state].nextState[1];
- stateplus2=fsmC[stateplus1].nextState[1];
-
-
int display0 = sprintf (buffer0, " Back Save");//convert integer to buffer str
@@ -1392,7 +1410,6 @@
yellowLED.period_us(25);// Set frequency at 40kHz
greenLED.period_us(25);// Set frequency at 40kHz
powerSaverCheck();
-
while(1) {
updateTime();