Keiarash Zoughi's Multi-Sensor for weather detection.
Dependencies: BMP180 N5110 mbed
Diff: main.cpp
- Revision:
- 4:47b0473fa81b
- Parent:
- 2:635c58eb70fb
- Child:
- 5:e75537898d23
--- a/main.cpp Wed May 06 14:02:16 2015 +0000 +++ b/main.cpp Thu May 07 16:02:05 2015 +0000 @@ -31,9 +31,59 @@ //boundary conditions - screen int cells[84][48]; + +void check(){ + lcd.clear(); + Redled.period(0.02); // set PWM period to 20ms + +Measurement measurement; // measurement structure declared in BMP180 class + + + // read values (T in Celsius and P in mb) and print over serial port + measurement = bmp180.readValues(); + serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); + + // 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 temperature = measurement.temperature; + // display on screen +// + float pressure = measurement.pressure; // same idea with floats + + + + if(measurement.temperature > 30 ){ + + lcd.printString("temperature high!",1,1); + + Redled=1.0; + + wait(3); } + + if(measurement.temperature < 3){ + + lcd.printString("temperature low!",1,1); + + Redled= 1.0; + + wait(3); } + +else { lcd.printString("temperature ok!",1,1); +wait(3); + } +} + + + + + + + + //shows pressure reading and temperature void measurement() -{ +{lcd.clear(); + Measurement measurement; // measurement structure declared in BMP180 class while(1) { @@ -57,12 +107,84 @@ } } +void temperature(){ + lcd.clear(); + Measurement measurement; // measurement structure declared in BMP180 class + while(1) { + + // read values (T in Celsius and P in mb) and print over serial port + measurement = bmp180.readValues(); + serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); + + 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 temperature = measurement.temperature; + int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer + // it is important the format specifier ensures the length will fit in the buffer + if (length <= 14) // if string will fit on display + lcd.printString(buffer,0,1); // + +} +} + +void pressure(){ + + lcd.clear(); + + Measurement measurement; // measurement structure declared in BMP180 class + while(1) { + + // read values (T in Celsius and P in mb) and print over serial port + measurement = bmp180.readValues(); + serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); + + 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 + +// + float pressure = measurement.pressure; // same idea with floats + length = sprintf(buffer,"P = %.2f mb",pressure); + if (length <= 14) + lcd.printString(buffer,0,2); + + + + +void altitude(){ // creating a new reading from the current ones, this appoximates the altitude in metres. + +lcd.clear(); + + Measurement measurement; // measurement structure declared in BMP180 class + +while(1){ + // read values (T in Celsius and P in mb) and print over serial port + measurement = bmp180.readValues(); + char buffer[14]; + int temperature = measurement.temperature; + float pressure = measurement.pressure; // same idea with floats + +float altitude = -(log(pressure/1013.25)*1.38e-23*temperature)/(9.81*28.95); +serial.printf("A = %.2f m",altitude); +int length = sprintf(buffer,"A = %.2f m",altitude); // print formatted data to buffer + // it is important the format specifier ensures the length will fit in the buffer +if (length <= 14) // if string wi + lcd.printString(buffer,0,1); // display on screen + + + + +} + +} //pushbutton - 0 //plots graph of temperature point by point void graph() -{ +{lcd.clear(); + Measurement measurement; // measurement structure declared in BMP180 class int i = 0; float graph[84]= {0}; @@ -96,28 +218,47 @@ } } -void settingScreen() -{ + + + + +void measurementsScreen() +{lcd.clear(); + lcd.printString("Hold Button!",1,1);//select measure menu +wait(1); +lcd.clear(); selectedOption = 0; - while(pushbutton1) { + while(1) { lcd.drawRect(70,6,10,10,1); lcd.drawRect(70,21,10,10,0); - lcd.printString("clock",1,1); + lcd.printString("temperature",1,1); lcd.printString(">",62,1); selectedOption = 1; - +if (pushbutton1) + break; wait(2); lcd.clear(); lcd.drawRect(70,6,10,10,0); lcd.drawRect(70,21,10,10,1); - lcd.printString("go back",1,3); + lcd.printString("altitude",1,3); lcd.printString(">",62,3); selectedOption = 2; +if (pushbutton1) + break; + wait(2); + lcd.clear(); +lcd.drawRect(70,6,10,10,0); + lcd.drawRect(70,21,10,10,1); + lcd.printString("pressure",1,3); + lcd.printString(">",62,3); + selectedOption = 2; +if (pushbutton1) + break; wait(2); lcd.clear(); @@ -125,14 +266,21 @@ if(selectedOption == 1) { - measurement(); + pressure(); } if(selectedOption == 2) { - graph(); + temperature(); } + +if(selectedOption == 3) { + + altitude(); + } + + } void introScreen() @@ -146,11 +294,64 @@ } + +void extrasScreen() +{lcd.clear(); + lcd.printString("Hold Button!",1,1);//select measure menu +wait(1); +lcd.clear(); + selectedOption = 0; + + while(1) { + + lcd.drawRect(70,6,10,10,1); + lcd.drawRect(70,21,10,10,0); + + lcd.printString("check",1,1); + lcd.printString(">",62,1); + selectedOption = 1; +if (pushbutton1) + break; + wait(2); + lcd.clear(); + + lcd.drawRect(70,6,10,10,0); + lcd.drawRect(70,21,10,10,1); + lcd.printString("go back",1,3); + lcd.printString(">",62,3); + selectedOption = 2; +if (pushbutton1) + break; + wait(2); + lcd.clear(); + + } + + if(selectedOption == 1) { + + lcd.clear(); + } + + if(selectedOption == 2) { + + lcd.clear(); + + } +} + + + void mainScreen() { + + lcd.printString("Hold Button!",1,1);//select measure menu + +wait(1); +lcd.clear(); + selectedOption = 0; - while(pushbutton1) {//initialse pushbutton as 0 + while(1) {//initialse pushbutton as 0 //check boxes-options to be selected lcd.drawRect(70,6,10,10,1);//check box 1 @@ -158,11 +359,13 @@ lcd.drawRect(70,37,10,10,0);//check box 3 //option titles-appropriate to check boxes - lcd.printString("measure",1,1);//select measure menu - lcd.printString("settings",1,3);//select settings menu - lcd.printString("graph",1,5);//select grpah plot + lcd.printString("extras",1,1);//select measure menu + lcd.printString("graph",1,3);//select settings menu + lcd.printString("measure",1,5);//select grpah plot lcd.printString(">",62,1);//pointer selectedOption = 1; + if (pushbutton1) + break; wait(2); lcd.clear(); @@ -172,11 +375,14 @@ lcd.drawRect(70,37,10,10,0); - lcd.printString("measure",1,1); - lcd.printString("settings",1,3); - lcd.printString("graph",1,5); + lcd.printString("extras",1,1); + lcd.printString("graph",1,3); + lcd.printString("measure",1,5); lcd.printString(">",62,3); selectedOption = 2; + if (pushbutton1) + break; + wait(2); lcd.clear(); @@ -186,11 +392,14 @@ lcd.drawRect(70,37,10,10,1); - lcd.printString("measure",1,1); - lcd.printString("settings",1,3); - lcd.printString("graph",1,5); + lcd.printString("extras",1,1); + lcd.printString("graph",1,3); + lcd.printString("measure",1,5); lcd.printString(">",62,5); selectedOption = 3; + if (pushbutton1) + break; + wait(2); lcd.clear(); @@ -200,12 +409,12 @@ if(selectedOption == 1) { - measurement(); + measurementsScreen(); } if(selectedOption == 2) { - settingScreen(); + extrasScreen(); } if(selectedOption == 3) { @@ -220,72 +429,9 @@ -void check(){ - - Redled.period(0.02); // set PWM period to 20ms - -Measurement measurement; // measurement structure declared in BMP180 class - - - // read values (T in Celsius and P in mb) and print over serial port - measurement = bmp180.readValues(); - serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); - - 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 temperature = measurement.temperature; - int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer - // it is important the format specifier ensures the length will fit in the buffer - if (length <= 14) // if string will fit on display - lcd.printString(buffer,0,1); // display on screen -// - float pressure = measurement.pressure; // same idea with floats - length = sprintf(buffer,"P = %.2f mb",pressure); - if (length <= 14) - lcd.printString(buffer,0,2); - - - if(measurement.temperature > 30 ){ - - lcd.printString("temperature high!",1,1); - - Redled=1.0; - - wait(3); } - - if(measurement.temperature < 3){ - - lcd.printString("temperature low!",1,1); - - Redled= 1.0; - - wait(3); } - -else { lcd.printString("temperature ok!",1,1); -wait(3); - } -} - void altitude(){ // creating a new reading from the current ones, this appoximates the altitude in metres. - - - - Measurement measurement; // measurement structure declared in BMP180 class - -while(1){ - // read values (T in Celsius and P in mb) and print over serial port - measurement = bmp180.readValues(); - - int temperature = measurement.temperature; - int pressure = measurement.pressure; // same idea with floats - -float altitude = -(log(pressure/1013.25)*1.38e-23*temperature)/(9.81*28.95); -serial.printf("A = %.2f metres",altitude); -} - -} + //main loop int main() @@ -302,5 +448,13 @@ mainScreen(); while(1) { + introScreen(); + wait(3); + Redled =0; + lcd.clear(); + mainScreen(); + + + } }