Program to display temperature and pressure readings along with date and time.
Dependencies: BMP180 N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 5:fb18fa86ebc3
- Parent:
- 4:f4154181d941
- Child:
- 6:49a3fb0956ef
--- a/main.cpp Wed Apr 29 16:08:18 2015 +0000 +++ b/main.cpp Wed Apr 29 16:35:44 2015 +0000 @@ -19,7 +19,7 @@ int timeOutFlag = 0 ; int graphFlag = 0 ; int currentFlag = 0; -int temperature ; +float temperature ; float pressure; void displayTemperature(); void displayPressure(); @@ -135,7 +135,7 @@ char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) // so can display a string of a maximum 14 characters in length // or create formatted strings - ensure they aren't more than 14 characters long - int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer + int length = sprintf(buffer,"T = %.2f C",temperature); // print formatted data to buffer // it is important the format specifier ensures the length will fit in the buffer serial.printf( " L %i",length); //used for debugging if (length <= 14) // if string will fit on display @@ -155,42 +155,45 @@ } -void displayTemperatureGraph() //function to display temperature graph ober the last hour +void displayTemperatureGraph() //function to display temperature graph { - float temperatureArray[84]; - int j=0; + float temperatureArray[84]; //maximum capacity of array is 84 + int j=0; //initialise j to 0 while(1) { - lcd.clear(); + lcd.clear(); //clear screen lcd.printString("Menu",0,5);//menu button label lcd.printString("Current",42,5);//current button label - receiveData(); - temperatureArray[j] = temperature; - j++; - lcd.plotArray(temperatureArray); - if (j>83) { - memset (temperatureArray,0, sizeof(temperatureArray)); + receiveData(); //get data from function + temperatureArray[j] = (temperature/50); //stores current temperature value in array + j++; //adds 1 to value of j to store next temperature value + lcd.plotArray(temperatureArray); //plots the array as a line + if (j>83) { //if the array is full + memset (temperatureArray,0, sizeof(temperatureArray)); //reset to 0 so line graph starts again j = 0; } - wait(0.1); + wait(0.1); //time inbetween each plot } } -void displayPressureGraph() //function to display pressure graph over the last day +void displayPressureGraph() //function to display pressure graph { - float pressureArray[84]; - int j=0; + float pressureArray[84]; //maximum capacity of array is 84 + int j=0; //initialise j to 0 while(1) { - lcd.clear(); - receiveData(); - pressureArray[j] = pressure/1100; - j++; - lcd.plotArray(pressureArray); - if (j>83) { + lcd.clear(); //clear screen + lcd.printString("Menu",0,5);//menu button label + lcd.printString("Current",42,5);//current button label + receiveData(); //get data from function + pressureArray[j] = (pressure/1100); //stores current pressure value in array + j++; //adds 1 to value of j to store next pressure value + lcd.plotArray(pressureArray); //plots the array as a line + if (j>83) { //if the array is full + memset (pressureArray,0, sizeof(pressureArray));//reset to 0 so line graph starts again j = 0; } - wait(1.0); + wait(0.1); //time inbetween each plot } }