
Temperature and Pressure logger.
Dependencies: BMP180 N5110 PowerControl beep mbed
Revision 0:ec64ecaac130, committed 2015-05-02
- Comitter:
- takis94
- Date:
- Sat May 02 23:17:39 2015 +0000
- Child:
- 1:d320c79324fe
- Commit message:
- finished
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BMP180.lib Sat May 02 23:17:39 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/eencae/code/BMP180/#9612c441a5a0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PowerControl.lib Sat May 02 23:17:39 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/JST2011/code/PowerControl/#d0fa2aeb02a4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beep.lib Sat May 02 23:17:39 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/pprasad7/code/beep/#080ef5594cce
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 02 23:17:39 2015 +0000 @@ -0,0 +1,848 @@ +/** +@file main.cpp + +@brief Program implementation + +*/ +#include "main.h" + +void update() +{ + if (temperature <= -20.0) { /// for temperatures -20 and below + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,0); /// x,y,radius,no fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + } + else if (temperature >-20.0 && temperature <= -10.0) { /// for temperatures between -20 and -10 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + } + else if (temperature >-10.0 && temperature <= 0.0) { /// for temperatures between -10 and 0 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + } + else if (temperature >0.0 && temperature <= 5.0) { /// for temperatures between 0 and 5 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + } + else if (temperature >5.0 && temperature <= 10.0) { /// for temperatures between 5 and 10 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + } + else if (temperature >10.0 && temperature <= 15.0) { /// for temperatures between 10 and 15 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); ///transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + } + else if (temperature >15.0 && temperature <= 20.0) { /// for temperatures between 15 and 20 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + lcd.setPixel(75,26); + lcd.setPixel(76,26); + lcd.setPixel(77,26); + lcd.setPixel(75,25); + lcd.setPixel(76,25); + lcd.setPixel(77,25); + } + else if (temperature >20.0 && temperature <= 25.0) { /// for temperatures between 20 and 25 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + lcd.setPixel(75,26); + lcd.setPixel(76,26); + lcd.setPixel(77,26); + lcd.setPixel(75,25); + lcd.setPixel(76,25); + lcd.setPixel(77,25); + } + else if (temperature >25.0 && temperature <= 30.0) { /// for temperatures between 25 and 30 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + lcd.setPixel(75,26); + lcd.setPixel(76,26); + lcd.setPixel(77,26); + lcd.setPixel(75,25); + lcd.setPixel(76,25); + lcd.setPixel(77,25); + lcd.setPixel(75,24); + lcd.setPixel(76,24); + lcd.setPixel(77,24); + lcd.setPixel(75,23); + lcd.setPixel(76,23); + lcd.setPixel(77,23); + + } + else if (temperature >30.0 && temperature <= 35.0) { /// for temperatures between 30 and 35 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + lcd.setPixel(75,26); + lcd.setPixel(76,26); + lcd.setPixel(77,26); + lcd.setPixel(75,25); + lcd.setPixel(76,25); + lcd.setPixel(77,25); + lcd.setPixel(75,24); + lcd.setPixel(76,24); + lcd.setPixel(77,24); + lcd.setPixel(75,23); + lcd.setPixel(76,23); + lcd.setPixel(77,23); + lcd.setPixel(75,22); + lcd.setPixel(76,22); + lcd.setPixel(77,22); + lcd.setPixel(75,21); + lcd.setPixel(76,21); + lcd.setPixel(77,21); + + } + else if (temperature >35.0 && temperature <= 40.0) { /// for temperatures between 35 and 40 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + lcd.setPixel(75,26); + lcd.setPixel(76,26); + lcd.setPixel(77,26); + lcd.setPixel(75,25); + lcd.setPixel(76,25); + lcd.setPixel(77,25); + lcd.setPixel(75,24); + lcd.setPixel(76,24); + lcd.setPixel(77,24); + lcd.setPixel(75,23); + lcd.setPixel(76,23); + lcd.setPixel(77,23); + lcd.setPixel(75,22); + lcd.setPixel(76,22); + lcd.setPixel(77,22); + lcd.setPixel(75,21); + lcd.setPixel(76,21); + lcd.setPixel(77,21); + lcd.setPixel(75,20); + lcd.setPixel(76,20); + lcd.setPixel(77,20); + lcd.setPixel(75,19); + lcd.setPixel(76,19); + lcd.setPixel(77,19); + + } + else if (temperature >40.0 && temperature <= 50.0) { /// for temperatures between 40 and 50 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + lcd.setPixel(75,26); + lcd.setPixel(76,26); + lcd.setPixel(77,26); + lcd.setPixel(75,25); + lcd.setPixel(76,25); + lcd.setPixel(77,25); + lcd.setPixel(75,24); + lcd.setPixel(76,24); + lcd.setPixel(77,24); + lcd.setPixel(75,23); + lcd.setPixel(76,23); + lcd.setPixel(77,23); + lcd.setPixel(75,22); + lcd.setPixel(76,22); + lcd.setPixel(77,22); + lcd.setPixel(75,21); + lcd.setPixel(76,21); + lcd.setPixel(77,21); + lcd.setPixel(75,20); + lcd.setPixel(76,20); + lcd.setPixel(77,20); + lcd.setPixel(75,19); + lcd.setPixel(76,19); + lcd.setPixel(77,19); + lcd.setPixel(75,18); + lcd.setPixel(76,18); + lcd.setPixel(77,18); + lcd.setPixel(75,17); + lcd.setPixel(76,17); + lcd.setPixel(77,17); + + } + else if (temperature >50.0 && temperature <= 65.0) { /// for temperatures between 50 and 65 + + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + + /* + int counnter_y = 34; + int counter_x = 75 + + while(counter_y >= 15) + + for(int i = counter_y; i<35; i++){ + + lcd.setPixel(counter_x,i); + + } + + counter_y = counter_y - 1; + counter_x = counter_x + 1; + + if(counter_x = 77){ + counter_x = 75; + } + */ + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + lcd.setPixel(75,32); + lcd.setPixel(76,32); + lcd.setPixel(77,32); + lcd.setPixel(75,31); + lcd.setPixel(76,31); + lcd.setPixel(77,31); + lcd.setPixel(75,30); + lcd.setPixel(76,30); + lcd.setPixel(77,30); + lcd.setPixel(75,29); + lcd.setPixel(76,29); + lcd.setPixel(77,29); + lcd.setPixel(75,28); + lcd.setPixel(76,28); + lcd.setPixel(77,28); + lcd.setPixel(75,27); + lcd.setPixel(76,27); + lcd.setPixel(77,27); + lcd.setPixel(75,26); + lcd.setPixel(76,26); + lcd.setPixel(77,26); + lcd.setPixel(75,25); + lcd.setPixel(76,25); + lcd.setPixel(77,25); + lcd.setPixel(75,24); + lcd.setPixel(76,24); + lcd.setPixel(77,24); + lcd.setPixel(75,23); + lcd.setPixel(76,23); + lcd.setPixel(77,23); + lcd.setPixel(75,22); + lcd.setPixel(76,22); + lcd.setPixel(77,22); + lcd.setPixel(75,21); + lcd.setPixel(76,21); + lcd.setPixel(77,21); + lcd.setPixel(75,20); + lcd.setPixel(76,20); + lcd.setPixel(77,20); + lcd.setPixel(75,19); + lcd.setPixel(76,19); + lcd.setPixel(77,19); + lcd.setPixel(75,18); + lcd.setPixel(76,18); + lcd.setPixel(77,18); + lcd.setPixel(75,17); + lcd.setPixel(76,17); + lcd.setPixel(77,17); + lcd.setPixel(75,16); + lcd.setPixel(76,16); + lcd.setPixel(77,16); + lcd.setPixel(75,15); + lcd.setPixel(76,15); + lcd.setPixel(77,15); + } +} + +void print() +{ + if(graphTempFlag == 0 && graphPresFlag == 0 && unitsFlag == 0) { ///no button is pressed or button 4 is pressed + + char buffer2[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 length = sprintf(buffer2,"T= %.2f 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(buffer2,0,1); /// display on screen + + length = sprintf(buffer2,"P= %.2fmb",pressure); ///print formatted data to buffer + if (length <= 14){ /// if string will fit on display + lcd.printString(buffer2,0,2); /// display on screen + lcd.printString(bufferT,0,4); /// display on screen + lcd.printString(bufferD,0,5); /// display on screen + } + lcd.drawLine(0,30,48,30,2); + lcd.drawLine(48,30,48,48,2); + ///draw the thermometer on the screen + /* + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + lcd.setPixel(75,34); + lcd.setPixel(76,34); + lcd.setPixel(77,34); + lcd.setPixel(75,33); + lcd.setPixel(76,33); + lcd.setPixel(77,33); + */ + update(); ///update thermometer + + ///set 0 degrees indicator + lcd.setPixel(72,33); + lcd.setPixel(71,33); + lcd.setPixel(70,33); + lcd.setPixel(69,33); + lcd.printChar('0',58,34); + + ///set 65 degrees indicator + lcd.setPixel(72,5); + lcd.setPixel(71,5); + lcd.setPixel(70,5); + lcd.setPixel(69,5); + lcd.printChar('5',62,6); + lcd.printChar('6',56,6); + + + if(temperature >15 && temperature <= 35){ ///good weather + ///draw a sun on screen + lcd.drawCircle(WIDTH/1.5,HEIGHT/1.2,2,1); /// x,y,radius,black fill + lcd.drawLine(53,40,59,40,1); + lcd.drawLine(56,37,56,43,1); + lcd.drawLine(53,37,59,43,1); + lcd.drawLine(59,37,53,43,1); + } + else if (temperature <= 15) { ///cold weather + ///draw a rainy cloud on screen + lcd.setPixel(57,37); + lcd.setPixel(56,37); + lcd.setPixel(56,36); + lcd.setPixel(55,37); + lcd.setPixel(58,42); + lcd.setPixel(58,38); + lcd.setPixel(58,37); + lcd.setPixel(54,44); + lcd.setPixel(59,44); + lcd.setPixel(60,47); + lcd.setPixel(56,45); + lcd.setPixel(61,45); + lcd.drawCircle(WIDTH/1.5,HEIGHT/1.2,2,1); /// x,y,radius,black fill + lcd.drawCircle(WIDTH/1.4,HEIGHT/1.2,2,1); /// x,y,radius,black fill + } + else { ///hot weather + ///draw a bigger sun on screen + lcd.drawCircle(WIDTH/1.5,HEIGHT/1.2,2,1); /// x,y,radius,black fill + lcd.drawLine(52,40,60,40,1); + lcd.drawLine(56,36,56,44,1); + lcd.drawLine(53,37,59,43,1); + lcd.drawLine(59,37,53,43,1); + } + + + } else if(graphTempFlag == 0 && graphPresFlag == 0 && unitsFlag) { ///button3 pressed + + char buffer2[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 length = sprintf(buffer2,"T= %.2f K",temperature+273.15); /// 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(buffer2,0,1); /// display on screen + } + length = sprintf(buffer2,"P= %.2f b",pressure/1000); /// print formatted data to buffer + if (length <= 14){ /// if string will fit on display + + lcd.printString(buffer2,0,2); /// display on screen + lcd.printString(bufferT,0,4); /// display on screen + lcd.printString(bufferD,0,5); /// display on screen + } + lcd.drawLine(0,30,48,30,2); + lcd.drawLine(48,30,48,48,2); + /* + ///draw the thermometer on screen + lcd.drawCircle(WIDTH/1.1,HEIGHT/1.2,5,1); /// x,y,radius,black fill + ///origin x,y,width,height,type + lcd.drawRect(74,5,4,30,0); /// transparent, just outline + */ + update(); ///update thermometer + + ///set 273.15K indicator + lcd.setPixel(72,33); + lcd.setPixel(71,33); + lcd.setPixel(70,33); + lcd.setPixel(69,33); + lcd.printString("273",46,34); + + ///set 338.15K indicator + lcd.setPixel(72,5); + lcd.setPixel(71,5); + lcd.setPixel(70,5); + lcd.setPixel(69,5); + lcd.printString("338",50,6); + + } else if(graphTempFlag && graphPresFlag == 0 && unitsFlag == 0) { ///if button is pressed + + char buffer3[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 tave; ///store average temperature + float t_sum=0; ///store sum of temperatures + float t_count=0; ///store position in the array + + for (int ind = 0; ind<84; ind++) { + if (array[ind] > 0) { + t_sum = t_sum + array[ind]*65; + t_count++; + } + } + tave = t_sum/t_count; + float length3 = sprintf(buffer3,"Tave = %.2f C",tave); /// print formatted data to buffer + /// it is important the format specifier ensures the length will fit in the buffer + if (length3 <= 14){ /// if string will fit on display + lcd.printString(buffer3,0,1); /// display on screen + } + if(temperature >15 && temperature <= 35){ + lcd.printString(" Good Weather",0,2); ///print string + } + else if (temperature <= 15) + lcd.printString(" Cold Weather",0,2); ///print string + else { + lcd.printString(" Hot Weather",0,2); ///print string + } + + } else if(graphTempFlag == 0 && graphPresFlag && unitsFlag == 0) { ///button2 pressed + + char buffer4[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 pave; ///store average pressure + float p_sum=0; ///store sum of presuures + float p_count=0; ///store position in the array2 + + for (int ind = 0; ind<84; ind++) { + if (array2[ind] > 0) { + p_sum = p_sum + array2[ind]*1100; + p_count++; + } + } + pave = p_sum/p_count; + float length4 = sprintf(buffer4,"Pave=%.2fmb",pave); /// print formatted data to buffer + /// it is important the format specifier ensures the length will fit in the buffer + if (length4 <= 14) { /// if string will fit on display + lcd.printString(buffer4,0,1); /// display on screen + } + if(pressure >999){ + lcd.printString("Clear Weather",0,2); ///print string + } + else if(pressure <= 999 && pressure >700){ + lcd.printString(" Windy/Cloudy",0,2); ///print string + } + else + lcd.printString("Rainy Weather",0,2); ///print string + } +} + +//ISR +void timerExpiredReading() +{ + readingFlag = 1; ///set flag to 1 +} +void timerExpiredTime() +{ + timerFlag = 1; ///set flag to 1 +} +void timeExpiredFiles() +{ + timerFilesFlag = 1; ///set flag to 1 +} +void buttonTempPressed() +{ + graphTempFlag = !graphTempFlag; ///toggle flag +} +void buttonPresPressed() +{ + graphPresFlag = !graphPresFlag; ///toggle flag +} +void buttonUnitsPressed() +{ + unitsFlag = !unitsFlag; ///toggle flag +} +void timerExpiredClear() +{ + clearFlag = 1; ///set flag to 1 +} + +int main() +{ + pc.baud(9600); ///set baud rate + /// first need to initialise display + lcd.init(); + /// initiliase barometer + bmp180.init(); + serial.attach(&serialISR); /// attach serial ISR + Measurement measurement; /// measurement structure declared in BMP180 class + ///PHY_PowerDown(); + timerClearScreen.attach(&timerExpiredClear,0.2); ///call ISR every 1 sec + timerReading.attach(&timerExpiredReading,10.0); ///call ISR every 10 sec + timerFiles.attach(&timeExpiredFiles,10.0); ///write data to file every 10 sec + ///set_time(1430606207); /// initialise time to 1st January 1970 + timer.attach(&timerExpiredTime,1.0); ///attach timer + + green = 0; ///set LED initially to 0 + red = 0; ///set LED initially to 0 + + button.rise(&buttonTempPressed); ///change the button state + button2.rise(&buttonPresPressed); ///change the button state + button3.rise(&buttonUnitsPressed); ///change the button state + + lcd.clear(); ///clear display + lcd.refresh(); ///refresh display + lcd.printString("WeatherStation",1,1); ///print string + lcd.printString(" by",1,2); ///print string + lcd.printString(" Panagiotis",1,3); ///print string + lcd.printString(" Rodosthenous",1,4); ///print string + lcd.printString("* * * * * * *",1,0); ///print string + lcd.printString("* * * * * * *",1,5); ///print string + ///Display to lcd the above details + wait(3); ///3 sec delay + lcd.clear(); ///clear display + lcd.refresh(); ///refresh display + + while(1) { + + if(clearFlag){ + clearFlag = 0; ///set flag to 0 + lcd.clear(); ///clear display + lcd.refresh(); ///refresh display + } + if(readingFlag) { + readingFlag = 0; + /// read values (T in Celsius and P in mb) and print over serial port + measurement = bmp180.readValues(); + temperature = measurement.temperature; + pressure = measurement.pressure; + serial.printf("T = %.2f C\nP = %.2f mb\n",measurement.temperature,measurement.pressure); //print measurements to serial + + if(i == 84) { + + for(int n = 0; n <= 82; n++) { + + array[n] = array[n+1]; + } + + for(int z = 0; z <= 82; z++) { + + array2[z] = array2[z+1]; + } + i = 83; + } + + array[i] = temperature/65; ///store temperature to array + array2[i] = pressure/1100; ///store pressure to array + i++; + } + + if(timerFlag) { + timerFlag = 0; ///set flag to 0 + time_t seconds = time(NULL); /// get current time + /// format time into a string (time and date) + strftime(bufferT, 14 , "%T", localtime(&seconds)); + strftime(bufferD, 14 , "%D", localtime(&seconds)); + /// print over serial + serial.printf("Time = %s\n",bufferT); ///print to pc + } + if (setTimeFlag) { /// if updated time has been sent + setTimeFlag = 0; /// clear flag + setTime(); /// update time + } + if(graphTempFlag) { + /// values must be in range 0.0 - 1.0 + lcd.plotArray(array); + lcd.normalMode(); /// normal colour mode back + button2.rise(NULL); ///disable interrupt + } else + button2.rise(&buttonPresPressed); ///enable interrupt + + if(graphPresFlag) { + /// values must be in range 0.0 - 1.0 + lcd.plotArray(array2); + lcd.normalMode(); /// normal colour mode back + button.rise(NULL); ///disable interrupt + } else + button.rise(&buttonTempPressed); ///enable interrupt + + if(temperature >= 35) { + buzzer.beep(1000,0.5); ///beep the buzzer if the temp is higher than a predetermined value + } + if(temperature >= 22 && temperature < 30) { + green = 1; ///light the LED if the temp is in the specific range + } else + green = 0; ///turn off the LED + + if(button4 == 1) { + graphTempFlag = 0; ///set flag to 0 + graphPresFlag = 0; ///set flag to 0 + unitsFlag = 0; ///set flag to 0 + + } + if(switch_logging == 1) { ///if switch is high + + if(timerFilesFlag) { + timerFilesFlag = 0; ///set flag to 0 + writeDataToFile(temperature,bufferT,pressure); //call function to write data to file + red = 1; ///light the red LED + } + } else red = 0; ///turn off the LED + + // Set Brightness + lcd.setBrightness(ain/3.2); ///set brightness according to the pot voltage + + print(); ///call print function + + Sleep(); ///put the processor on sleep mode + } +} + +void setTime() +{ +/// print time for debugging + serial.printf("set_time - %s",rxString); +/// atoi() converts a string to an integer + int time = atoi(rxString); +/// update the time + set_time(time); +} +void serialISR() +{ +/// when a serial interrupt occurs, read rx string into buffer + serial.gets(rxString,16); +/// set flag + setTimeFlag = 1; +} +void writeDataToFile(float tempereture,char* time,float pressure) +{ + leds = 15; /// turn on LEDs for feedback + FILE *fp = fopen("/local/log.csv", "a"); /// open 'log.csv' for appending +/// if the file doesn't exist it is created, if it exists, data is appended to the end + fprintf(fp,"%s , %.2f\t, %.2f\n",time,tempereture,pressure); /// print string to file + fclose(fp); /// close file + leds = 0; /// turn off LEDs to signify file access has finished +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Sat May 02 23:17:39 2015 +0000 @@ -0,0 +1,251 @@ +/** +@file main.h +@brief Header file containing functions prototypes, defines and global variables. +@brief Doxygen documentation. +@brief Wheather Station. +@author Panayiotis Rodosthenous +@date March 2015 +*/ + +#ifndef MAIN_H +#define MAIN_H + +#define PI 3.14159265359 + +#include "mbed.h" +#include "N5110.h" +#include "BMP180.h" +#include "PowerControl/PowerControl.h" +#include "PowerControl/EthernetPowerControl.h" +#include "beep.h" + +/** +@namespace bmp180 +@brief Assign sensor pins to the mbed +*/ +BMP180 bmp180(p28,p27); // SDA, SCL + +/** +@namespace serial +@brief Serial connection for presenting data to pc +*/ +Serial serial(USBTX,USBRX); //tx,rx + +/** +@namespace pc +@brief Serial connection for presenting data to serial +*/ +Serial pc(USBTX,USBRX); //tx,rx + +/** +@namespace lcd +@brief Assign the LCD pins to the mbed +*/ +N5110 lcd(p7,p8,p9,p10,p11,p13,p26); ///VCC,SCE,RST,D/C,MOSI,SCLK,LED + +/** +@namespace local +@brief Location to create a file for data logging +*/ +LocalFileSystem local("local"); + +/** +@namespace buzzer +@brief GPIO output for warning buzzer +*/ +Beep buzzer(p21); + +/** +@namespace button4 +@brief GPIO input for main screen button +*/ +DigitalIn button4(p19); + +/** +@namespace button +@brief ISR input for temperature graph button +*/ +InterruptIn button(p18); + +/** +@namespace button2 +@brief ISR input for pressure graph button +*/ +InterruptIn button2(p17); + +/** +@namespace button3 +@brief ISR input for changing the units button +*/ +InterruptIn button3(p16); + +/** +@namespace switch_logging +@brief GPIO input for data logging switch +*/ +DigitalIn switch_logging(p15); + +/** +@namespace ain +@brief GPIO analogue input for brightness potentiometer +*/ +AnalogIn ain(p20); + +/** +@namespace green +@brief GPIO output for status green LED +*/ +DigitalOut green(p25); + +/** +@namespace red +@brief GPIO output for status red LED +*/ +DigitalOut red(p24); + +/** +@namespace leds +@brief Bus output for status on-board LED +*/ +BusOut leds(LED4,LED3,LED2,LED1); //bus for on-board LEDs + +/** +@namespace timerReading +@brief Ticker for reading the sensor +*/ +Ticker timerReading; + +/** +@namespace timer +@brief Ticker for getting current time +*/ +Ticker timer; + +/** +@namespace timerFiles +@brief Ticker for writing data to file +*/ +Ticker timerFiles; + +/** +@namespace timerClearScreen +@brief Ticker for clearing the LCD +*/ +Ticker timerClearScreen; + +int readingFlag = 0; /*!< reading flag set in ISR */ +int timerFlag = 0; /*!< timer flag set in ISR */ +int timerFilesFlag = 0; /*!< timerFiles flag set in ISR */ +int setTimeFlag = 0; /*!< setTime flag set in ISR */ +int graphTempFlag = 0; /*!< graphTemp flag set in ISR */ +int graphPresFlag = 0; /*!< graphPres flag set in ISR */ +int unitsFlag = 0; /*!< units flag set in ISR */ +int clearFlag = 0; /*!< celar flag set in ISR */ +int i = 0; /*!< variable i used as index in print() */ + +char rxString[16]; /*!< string used to transfer current time into the buffer */ +char bufferT[14]; /*!< buffer used to store current time */ +char bufferD[14]; /*!< buffer used to store current date */ + +float temperature; /*!< variable used to store current temperature */ +float pressure; /*!< variable used to store current pressure */ +float array[84]; /*!< array used to store temperature readings */ +float array2[84]; /*!< array used to store pressure readings */ + +/** Update + * + * Prints and updates the thermometer presented on the main screen. + * For each specified range of temperatures adds or removes pixels from inside the thermometer. + * Introduces a live update on the main screen. + */ +void update(); + +/** Print + * + * Prints the different screens on the LCD. + * According to the buttons status-flags, a different screen is presented. Buttons are used as interrupts. + * Includes the update() function. + * -Button 1: Print the temperature graph with the average temperature and weather prediction. Disables button 2. + * -Button 2: Print the pressure graph with the average pressure and weather prediction. Disables button 1. + * -Button 3: Converts the temperature and pressure units on the main screen. When one of buttons 1 or 2 is previously pressed, it removes the average and weather predictions from screen. + * -No button pressed: Displays the main screen. + */ +void print(); + +/** Write Data to File + * + * Logs the time, temperature and pressure on a .csv file on the mbed Flash memory. + * It called when the logging switch is ON. + * A ticker is used to call this function. Logs data every 10 sec. + * @param time - the current time taken from setTime() function. + * @param temperature - the current temperature read from sensor. + * @param temperature - the current tpressure read from sensor. + * @returns + * log.csv - file with parameters in comma separated format stored on mbed. + */ +void writeDataToFile(float tempereture,char* time,float pressure); + +/** Serial ISR + * + * This is an ISR function, called when serial data is received. + * Gets the time rxString. + */ +void serialISR(); + +/** Set Time + * + * This function sets the UNIX time. + * Updates the time, bu converting the time string into an integer value. + */ +void setTime(); + +/** Timer Expired Reading + * + * This function sets the reading flag high when called. + * Attached to the timerReading ticker. + */ +void timerExpiredReading(); + +/** Timer Expired Time + * + * This function sets the timer flag high when called. + * Attached to the timer ticker. + */ +void timerExpiredTime(); + +/** Timer Expired Files + * + * This function sets the timerFiles flag high when called. + * Attached to the timerFiles ticker. + */ +void timeExpiredFiles(); + +/** Timer Expired Clear + * + * This function sets the clear flag high when called. + * Attached to the clearScreen ticker. + */ +void timerExpiredClear(); + +/** Button for Temperature Pressed + * + * This function toggles the graphTemp flag when button is pressed. + * Attached to the button interrupt configuration. + */ +void buttonTempPressed(); + +/** Button for Pressure Pressed + * + * This function toggles the graphPres flag when button2 is pressed. + * Attached to the button2 interrupt configuration. + */ +void buttonPresPressed(); + +/** Button for Units Pressed + * + * This function toggles the units flag when button3 is pressed. + * Attached to the button3 interrupt configuration. + */ +void buttonUnitsPressed(); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat May 02 23:17:39 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf \ No newline at end of file