Keiarash Zoughi's Multi-Sensor for weather detection.

Dependencies:   BMP180 N5110 mbed

Committer:
el13kz
Date:
Fri May 08 15:54:39 2015 +0000
Revision:
9:5ebf44c85f77
Parent:
8:956a130ebdf5
Child:
10:d62ac368381c
badman

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el13kz 0:771a5148e8e7 1 #include "mbed.h"
el13kz 0:771a5148e8e7 2 #include "N5110.h"
el13kz 0:771a5148e8e7 3 #include "BMP180.h"
el13kz 0:771a5148e8e7 4
el13kz 0:771a5148e8e7 5 #define PI 3.14159265359
el13kz 2:635c58eb70fb 6
el13kz 2:635c58eb70fb 7 //LCD inputs
el13kz 2:635c58eb70fb 8 N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
el13kz 2:635c58eb70fb 9
el13kz 2:635c58eb70fb 10 //serial port for debugging
el13kz 2:635c58eb70fb 11 Serial serial(USBTX,USBRX);
el13kz 2:635c58eb70fb 12
el13kz 2:635c58eb70fb 13 //LED outputs
el13kz 0:771a5148e8e7 14 BusOut leds(LED4,LED3,LED2,LED1); // LEDs for display
el13kz 0:771a5148e8e7 15
el13kz 2:635c58eb70fb 16
el13kz 2:635c58eb70fb 17 //select button
el13kz 0:771a5148e8e7 18 DigitalIn pushbutton1(p19);
el13kz 2:635c58eb70fb 19
el13kz 2:635c58eb70fb 20
el13kz 2:635c58eb70fb 21 //barometer sensor input
el13kz 0:771a5148e8e7 22 BMP180 bmp180(p28,p27); // SDA, SCL
el13kz 2:635c58eb70fb 23
el13kz 2:635c58eb70fb 24 //warning LED
el13kz 2:635c58eb70fb 25 PwmOut Redled(p24);
el13kz 2:635c58eb70fb 26
el13kz 2:635c58eb70fb 27 //globals
el13kz 9:5ebf44c85f77 28 int selectedOption1 = 0;
el13kz 0:771a5148e8e7 29 int buttonPressed = 0;
el13kz 9:5ebf44c85f77 30 int selectedOption2 = 0;
el13kz 9:5ebf44c85f77 31 int selectedOption3 = 0;
el13kz 9:5ebf44c85f77 32 int selectedOption4 = 0;
el13kz 0:771a5148e8e7 33
el13kz 2:635c58eb70fb 34 //boundary conditions - screen
el13kz 2:635c58eb70fb 35 int cells[84][48];
el13kz 2:635c58eb70fb 36
el13kz 9:5ebf44c85f77 37 Timer t1;
el13kz 9:5ebf44c85f77 38 Timer t2;
el13kz 9:5ebf44c85f77 39 Timer t3;
el13kz 9:5ebf44c85f77 40 Timer t4;
el13kz 9:5ebf44c85f77 41 Timer t5;
el13kz 9:5ebf44c85f77 42 Timer t6;
el13kz 9:5ebf44c85f77 43
el13kz 4:47b0473fa81b 44
el13kz 6:07133c44d3eb 45 void check()
el13kz 6:07133c44d3eb 46 {
el13kz 4:47b0473fa81b 47 lcd.clear();
el13kz 4:47b0473fa81b 48
el13kz 6:07133c44d3eb 49 Measurement measurement; // measurement structure declared in BMP180 class
el13kz 6:07133c44d3eb 50
el13kz 4:47b0473fa81b 51
el13kz 6:07133c44d3eb 52 // read values (T in Celsius and P in mb) and print over serial port
el13kz 6:07133c44d3eb 53 measurement = bmp180.readValues();
el13kz 6:07133c44d3eb 54 serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
el13kz 4:47b0473fa81b 55
el13kz 6:07133c44d3eb 56 // so can display a string of a maximum 14 characters in length
el13kz 6:07133c44d3eb 57 // or create formatted strings - ensure they aren't more than 14 characters long
el13kz 6:07133c44d3eb 58 float temperature = measurement.temperature;
el13kz 6:07133c44d3eb 59 // display on screen
el13kz 7:c39d54bdff28 60 char buffer[14]; // each charact
el13kz 7:c39d54bdff28 61 int length = sprintf(buffer,"T = %.2f C",temperature); // print formatted data to buffer
el13kz 7:c39d54bdff28 62 // it is important the format specifier ensures the length will fit in the buffer
el13kz 7:c39d54bdff28 63 if (length <= 14) // if string will fit on display
el13kz 7:c39d54bdff28 64 lcd.printString(buffer,0,5); // display on screen
el13kz 7:c39d54bdff28 65
el13kz 7:c39d54bdff28 66
el13kz 4:47b0473fa81b 67
el13kz 6:07133c44d3eb 68 if(temperature > 30.0 ) {
el13kz 4:47b0473fa81b 69
el13kz 7:c39d54bdff28 70 lcd.printString("TEMP HIGH!",1,1);
el13kz 7:c39d54bdff28 71 Redled=1.0;
el13kz 4:47b0473fa81b 72
el13kz 4:47b0473fa81b 73
el13kz 4:47b0473fa81b 74
el13kz 6:07133c44d3eb 75 } else if(temperature < 3.0) {
el13kz 4:47b0473fa81b 76
el13kz 7:c39d54bdff28 77 lcd.printString("TEMP LOW!",1,1);
el13kz 6:07133c44d3eb 78 Redled= 1.0;
el13kz 6:07133c44d3eb 79
el13kz 4:47b0473fa81b 80
el13kz 6:07133c44d3eb 81 } else {
el13kz 7:c39d54bdff28 82 lcd.printString("TEMP OK!",1,1);
el13kz 7:c39d54bdff28 83 Redled = 0.0;
el13kz 6:07133c44d3eb 84 }
el13kz 7:c39d54bdff28 85
el13kz 7:c39d54bdff28 86
el13kz 6:07133c44d3eb 87 wait(3);
el13kz 7:c39d54bdff28 88 lcd.clear();
el13kz 7:c39d54bdff28 89
el13kz 7:c39d54bdff28 90
el13kz 4:47b0473fa81b 91 }
el13kz 4:47b0473fa81b 92
el13kz 9:5ebf44c85f77 93 void pie(){
el13kz 9:5ebf44c85f77 94 lcd.clear();
el13kz 9:5ebf44c85f77 95 // example of how to draw circles
el13kz 9:5ebf44c85f77 96
el13kz 9:5ebf44c85f77 97 lcd.drawCircle(42,24,22,0); // x,y,radius,transparent with outline
el13kz 9:5ebf44c85f77 98
el13kz 9:5ebf44c85f77 99
el13kz 9:5ebf44c85f77 100 for (int x = 0; x < WIDTH ; x+=10) {
el13kz 9:5ebf44c85f77 101 // x0,y0,x1,y1,type 0-white,1-black,2-dotted
el13kz 9:5ebf44c85f77 102 lcd.drawLine(42,24,62,14,1);
el13kz 9:5ebf44c85f77 103 lcd.drawLine(42,24,62,34,1);
el13kz 4:47b0473fa81b 104
el13kz 4:47b0473fa81b 105
el13kz 4:47b0473fa81b 106
el13kz 4:47b0473fa81b 107
el13kz 4:47b0473fa81b 108
el13kz 9:5ebf44c85f77 109 }
el13kz 9:5ebf44c85f77 110 wait(5);
el13kz 9:5ebf44c85f77 111
el13kz 9:5ebf44c85f77 112 lcd.clear();
el13kz 9:5ebf44c85f77 113 }
el13kz 4:47b0473fa81b 114
el13kz 4:47b0473fa81b 115
el13kz 7:c39d54bdff28 116
el13kz 2:635c58eb70fb 117 //shows pressure reading and temperature
el13kz 0:771a5148e8e7 118 void measurement()
el13kz 6:07133c44d3eb 119 {
el13kz 6:07133c44d3eb 120 lcd.clear();
el13kz 4:47b0473fa81b 121
el13kz 0:771a5148e8e7 122 Measurement measurement; // measurement structure declared in BMP180 class
el13kz 0:771a5148e8e7 123 while(1) {
el13kz 0:771a5148e8e7 124
el13kz 0:771a5148e8e7 125 // read values (T in Celsius and P in mb) and print over serial port
el13kz 0:771a5148e8e7 126 measurement = bmp180.readValues();
el13kz 0:771a5148e8e7 127 serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
el13kz 0:771a5148e8e7 128
el13kz 0:771a5148e8e7 129 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
el13kz 0:771a5148e8e7 130 // so can display a string of a maximum 14 characters in length
el13kz 0:771a5148e8e7 131 // or create formatted strings - ensure they aren't more than 14 characters long
el13kz 0:771a5148e8e7 132 int temperature = measurement.temperature;
el13kz 0:771a5148e8e7 133 int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
el13kz 0:771a5148e8e7 134 // it is important the format specifier ensures the length will fit in the buffer
el13kz 0:771a5148e8e7 135 if (length <= 14) // if string will fit on display
el13kz 0:771a5148e8e7 136 lcd.printString(buffer,0,1); // display on screen
el13kz 0:771a5148e8e7 137 //
el13kz 0:771a5148e8e7 138 float pressure = measurement.pressure; // same idea with floats
el13kz 0:771a5148e8e7 139 length = sprintf(buffer,"P = %.2f mb",pressure);
el13kz 0:771a5148e8e7 140 if (length <= 14)
el13kz 0:771a5148e8e7 141 lcd.printString(buffer,0,2);
el13kz 0:771a5148e8e7 142 }
el13kz 0:771a5148e8e7 143 }
el13kz 0:771a5148e8e7 144
el13kz 6:07133c44d3eb 145 void temperature()
el13kz 6:07133c44d3eb 146 {
el13kz 6:07133c44d3eb 147 lcd.clear();
el13kz 0:771a5148e8e7 148
el13kz 4:47b0473fa81b 149 Measurement measurement; // measurement structure declared in BMP180 class
el13kz 9:5ebf44c85f77 150 t1.start();
el13kz 9:5ebf44c85f77 151 while(t1.read()<5) {
el13kz 4:47b0473fa81b 152
el13kz 4:47b0473fa81b 153 // read values (T in Celsius and P in mb) and print over serial port
el13kz 4:47b0473fa81b 154 measurement = bmp180.readValues();
el13kz 4:47b0473fa81b 155 serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
el13kz 4:47b0473fa81b 156
el13kz 4:47b0473fa81b 157 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
el13kz 4:47b0473fa81b 158 // so can display a string of a maximum 14 characters in length
el13kz 4:47b0473fa81b 159 // or create formatted strings - ensure they aren't more than 14 characters long
el13kz 4:47b0473fa81b 160 int temperature = measurement.temperature;
el13kz 4:47b0473fa81b 161 int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
el13kz 4:47b0473fa81b 162 // it is important the format specifier ensures the length will fit in the buffer
el13kz 4:47b0473fa81b 163 if (length <= 14) // if string will fit on display
el13kz 6:07133c44d3eb 164 lcd.printString(buffer,0,1); //
el13kz 6:07133c44d3eb 165
el13kz 6:07133c44d3eb 166 }
el13kz 9:5ebf44c85f77 167 t1.stop();
el13kz 8:956a130ebdf5 168 lcd.clear();
el13kz 9:5ebf44c85f77 169
el13kz 4:47b0473fa81b 170 }
el13kz 4:47b0473fa81b 171
el13kz 6:07133c44d3eb 172 void pressure()
el13kz 6:07133c44d3eb 173 {
el13kz 6:07133c44d3eb 174 lcd.clear();
el13kz 4:47b0473fa81b 175
el13kz 4:47b0473fa81b 176 Measurement measurement; // measurement structure declared in BMP180 class
el13kz 8:956a130ebdf5 177
el13kz 9:5ebf44c85f77 178 t2.start();
el13kz 8:956a130ebdf5 179
el13kz 9:5ebf44c85f77 180 while(t2.read()<5) {
el13kz 4:47b0473fa81b 181
el13kz 4:47b0473fa81b 182 // read values (T in Celsius and P in mb) and print over serial port
el13kz 4:47b0473fa81b 183 measurement = bmp180.readValues();
el13kz 4:47b0473fa81b 184 serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
el13kz 4:47b0473fa81b 185
el13kz 4:47b0473fa81b 186 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
el13kz 4:47b0473fa81b 187 // so can display a string of a maximum 14 characters in length
el13kz 4:47b0473fa81b 188 // or create formatted strings - ensure they aren't more than 14 characters long
el13kz 6:07133c44d3eb 189
el13kz 4:47b0473fa81b 190 //
el13kz 4:47b0473fa81b 191 float pressure = measurement.pressure; // same idea with floats
el13kz 5:e75537898d23 192 int length = sprintf(buffer,"P = %.2f mb",pressure);
el13kz 4:47b0473fa81b 193 if (length <= 14)
el13kz 8:956a130ebdf5 194 lcd.printString(buffer,0,1);
el13kz 6:07133c44d3eb 195 }
el13kz 9:5ebf44c85f77 196 t2.stop();
el13kz 8:956a130ebdf5 197 lcd.clear();
el13kz 8:956a130ebdf5 198
el13kz 5:e75537898d23 199 }
el13kz 4:47b0473fa81b 200
el13kz 4:47b0473fa81b 201
el13kz 4:47b0473fa81b 202
el13kz 6:07133c44d3eb 203 void altitude() // creating a new reading from the current ones, this appoximates the altitude in metres.
el13kz 6:07133c44d3eb 204 {
el13kz 4:47b0473fa81b 205
el13kz 6:07133c44d3eb 206 lcd.clear();
el13kz 4:47b0473fa81b 207
el13kz 4:47b0473fa81b 208 Measurement measurement; // measurement structure declared in BMP180 class
el13kz 6:07133c44d3eb 209
el13kz 8:956a130ebdf5 210
el13kz 9:5ebf44c85f77 211 t3.start();
el13kz 8:956a130ebdf5 212
el13kz 9:5ebf44c85f77 213 while(t3.read()<5) {
el13kz 4:47b0473fa81b 214 // read values (T in Celsius and P in mb) and print over serial port
el13kz 4:47b0473fa81b 215 measurement = bmp180.readValues();
el13kz 4:47b0473fa81b 216 char buffer[14];
el13kz 4:47b0473fa81b 217 int temperature = measurement.temperature;
el13kz 4:47b0473fa81b 218 float pressure = measurement.pressure; // same idea with floats
el13kz 4:47b0473fa81b 219
el13kz 6:07133c44d3eb 220 float altitude = -(log(pressure/1013.25)*1.38e-23*temperature)/(9.81*28.95);
el13kz 6:07133c44d3eb 221 serial.printf("A = %.2f m",altitude);
el13kz 6:07133c44d3eb 222 int length = sprintf(buffer,"A = %.2f m",altitude); // print formatted data to buffer
el13kz 4:47b0473fa81b 223 // it is important the format specifier ensures the length will fit in the buffer
el13kz 6:07133c44d3eb 224 if (length <= 14) // if string wi
el13kz 4:47b0473fa81b 225 lcd.printString(buffer,0,1); // display on screen
el13kz 4:47b0473fa81b 226
el13kz 4:47b0473fa81b 227
el13kz 9:5ebf44c85f77 228 lcd.drawLine(4,48,24,28,1);
el13kz 9:5ebf44c85f77 229 lcd.drawLine(24,28,44,48,1);
el13kz 9:5ebf44c85f77 230 lcd.drawLine(34,38,44,28,1);
el13kz 9:5ebf44c85f77 231 lcd.drawLine(44,28,64,48,1);
el13kz 9:5ebf44c85f77 232
el13kz 4:47b0473fa81b 233
el13kz 4:47b0473fa81b 234
el13kz 6:07133c44d3eb 235 }
el13kz 9:5ebf44c85f77 236 t3.stop();
el13kz 8:956a130ebdf5 237 lcd.clear();
el13kz 4:47b0473fa81b 238
el13kz 4:47b0473fa81b 239 }
el13kz 2:635c58eb70fb 240 //pushbutton - 0
el13kz 0:771a5148e8e7 241
el13kz 2:635c58eb70fb 242 //plots graph of temperature point by point
el13kz 0:771a5148e8e7 243 void graph()
el13kz 6:07133c44d3eb 244 {
el13kz 6:07133c44d3eb 245 lcd.clear();
el13kz 4:47b0473fa81b 246
el13kz 0:771a5148e8e7 247 Measurement measurement; // measurement structure declared in BMP180 class
el13kz 0:771a5148e8e7 248 int i = 0;
el13kz 0:771a5148e8e7 249 float graph[84]= {0};
el13kz 7:c39d54bdff28 250
el13kz 7:c39d54bdff28 251
el13kz 9:5ebf44c85f77 252 t4.start();
el13kz 9:5ebf44c85f77 253 while(t4.read()<15) {
el13kz 0:771a5148e8e7 254
el13kz 0:771a5148e8e7 255 // read values (T in Celsius and P in mb) and print over serial port
el13kz 0:771a5148e8e7 256 measurement = bmp180.readValues();
el13kz 0:771a5148e8e7 257 //serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
el13kz 0:771a5148e8e7 258
el13kz 0:771a5148e8e7 259 // so can display a string of a maximum 14 characters in length
el13kz 0:771a5148e8e7 260 // or create formatted strings - ensure they aren't more than 14 characters long
el13kz 0:771a5148e8e7 261 int temperature = measurement.temperature;
el13kz 0:771a5148e8e7 262 // int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
el13kz 0:771a5148e8e7 263 // it is important the format specifier ensures the length will fit in the buffer
el13kz 0:771a5148e8e7 264 // if (length <= 14) // if string will fit on display
el13kz 0:771a5148e8e7 265 // lcd.printString(buffer,0,1); // display on screen
el13kz 0:771a5148e8e7 266 //
el13kz 0:771a5148e8e7 267 // float pressure = measurement.pressure; // same idea with floats
el13kz 0:771a5148e8e7 268 // length = sprintf(buffer,"P = %.2f mb",pressure);
el13kz 0:771a5148e8e7 269 // if (length <= 14)
el13kz 0:771a5148e8e7 270 // lcd.printString(buffer,0,2);
el13kz 0:771a5148e8e7 271
el13kz 0:771a5148e8e7 272 graph[i]= temperature ;
el13kz 0:771a5148e8e7 273 lcd.plotArray(graph);
el13kz 0:771a5148e8e7 274 wait(0.1); // short delay until next reading
el13kz 0:771a5148e8e7 275 i++;
el13kz 0:771a5148e8e7 276 if (i>83) {
el13kz 0:771a5148e8e7 277 i=0;
el13kz 0:771a5148e8e7 278 lcd.clear();
el13kz 0:771a5148e8e7 279 }
el13kz 0:771a5148e8e7 280 }
el13kz 8:956a130ebdf5 281
el13kz 9:5ebf44c85f77 282 t4.stop();
el13kz 8:956a130ebdf5 283
el13kz 8:956a130ebdf5 284 lcd.clear();
el13kz 0:771a5148e8e7 285 }
el13kz 0:771a5148e8e7 286
el13kz 6:07133c44d3eb 287
el13kz 8:956a130ebdf5 288
el13kz 8:956a130ebdf5 289
el13kz 7:c39d54bdff28 290 void graphScreen(){
el13kz 7:c39d54bdff28 291
el13kz 7:c39d54bdff28 292 lcd.clear();
el13kz 7:c39d54bdff28 293 lcd.printString("Hold button!",6,2);//select measure menu
el13kz 7:c39d54bdff28 294 wait(1);
el13kz 7:c39d54bdff28 295 lcd.clear();
el13kz 9:5ebf44c85f77 296 selectedOption1 = 0;
el13kz 7:c39d54bdff28 297
el13kz 7:c39d54bdff28 298 while(1) {
el13kz 7:c39d54bdff28 299
el13kz 7:c39d54bdff28 300 lcd.drawRect(70,6,10,10,1);
el13kz 7:c39d54bdff28 301 lcd.drawRect(70,21,10,10,0);
el13kz 7:c39d54bdff28 302 lcd.drawRect(70,37,10,10,0);//check box 3
el13kz 7:c39d54bdff28 303 lcd.printString("line graph",1,1);
el13kz 7:c39d54bdff28 304 lcd.printString("pie chart",1,3);
el13kz 7:c39d54bdff28 305 lcd.printString("go back",1,5);
el13kz 7:c39d54bdff28 306
el13kz 7:c39d54bdff28 307 lcd.printString(">",62,1);
el13kz 9:5ebf44c85f77 308 selectedOption1 = 1;
el13kz 7:c39d54bdff28 309 if (pushbutton1)
el13kz 7:c39d54bdff28 310 break;
el13kz 7:c39d54bdff28 311 wait(2);
el13kz 7:c39d54bdff28 312 lcd.clear();
el13kz 7:c39d54bdff28 313
el13kz 7:c39d54bdff28 314 lcd.drawRect(70,6,10,10,0);
el13kz 7:c39d54bdff28 315 lcd.drawRect(70,21,10,10,1);
el13kz 7:c39d54bdff28 316 lcd.drawRect(70,37,10,10,0);//check box 3
el13kz 7:c39d54bdff28 317 lcd.printString("line graph",1,1);
el13kz 8:956a130ebdf5 318 lcd.printString("pie chart",1,3);
el13kz 7:c39d54bdff28 319
el13kz 8:956a130ebdf5 320 lcd.printString("go back",1,5);
el13kz 7:c39d54bdff28 321 lcd.printString(">",62,3);
el13kz 9:5ebf44c85f77 322 selectedOption1 = 2;
el13kz 7:c39d54bdff28 323 if (pushbutton1)
el13kz 7:c39d54bdff28 324 break;
el13kz 7:c39d54bdff28 325 wait(2);
el13kz 7:c39d54bdff28 326 lcd.clear();
el13kz 7:c39d54bdff28 327
el13kz 7:c39d54bdff28 328 lcd.drawRect(70,6,10,10,0);
el13kz 7:c39d54bdff28 329 lcd.drawRect(70,21,10,10,0);
el13kz 7:c39d54bdff28 330 lcd.drawRect(70,37,10,10,1);//check box 3
el13kz 7:c39d54bdff28 331 lcd.printString("line graph",1,1);
el13kz 7:c39d54bdff28 332 lcd.printString("pie chart",1,3);
el13kz 7:c39d54bdff28 333 lcd.printString("go back",1,5);
el13kz 7:c39d54bdff28 334 lcd.printString(">",62,5);
el13kz 9:5ebf44c85f77 335 selectedOption1 = 3;
el13kz 7:c39d54bdff28 336 if (pushbutton1)
el13kz 7:c39d54bdff28 337 break;
el13kz 7:c39d54bdff28 338 wait(2);
el13kz 7:c39d54bdff28 339 lcd.clear();
el13kz 7:c39d54bdff28 340
el13kz 7:c39d54bdff28 341 }
el13kz 7:c39d54bdff28 342
el13kz 9:5ebf44c85f77 343 if(selectedOption1 == 1) {
el13kz 7:c39d54bdff28 344
el13kz 7:c39d54bdff28 345 lcd.clear();
el13kz 7:c39d54bdff28 346 }
el13kz 7:c39d54bdff28 347
el13kz 9:5ebf44c85f77 348 if(selectedOption1 == 2) {
el13kz 7:c39d54bdff28 349
el13kz 7:c39d54bdff28 350 graph();
el13kz 7:c39d54bdff28 351
el13kz 7:c39d54bdff28 352 }
el13kz 7:c39d54bdff28 353
el13kz 9:5ebf44c85f77 354 if(selectedOption1 == 3) {
el13kz 7:c39d54bdff28 355
el13kz 9:5ebf44c85f77 356 pie();
el13kz 7:c39d54bdff28 357 }
el13kz 7:c39d54bdff28 358
el13kz 7:c39d54bdff28 359
el13kz 7:c39d54bdff28 360 }
el13kz 4:47b0473fa81b 361
el13kz 4:47b0473fa81b 362
el13kz 4:47b0473fa81b 363
el13kz 4:47b0473fa81b 364 void measurementsScreen()
el13kz 6:07133c44d3eb 365 {
el13kz 6:07133c44d3eb 366 lcd.clear();
el13kz 6:07133c44d3eb 367 lcd.printString("Hold button!",6,2);//select measure menu
el13kz 6:07133c44d3eb 368 wait(1);
el13kz 6:07133c44d3eb 369 lcd.clear();
el13kz 9:5ebf44c85f77 370 selectedOption2 = 0;
el13kz 0:771a5148e8e7 371
el13kz 4:47b0473fa81b 372 while(1) {
el13kz 0:771a5148e8e7 373
el13kz 2:635c58eb70fb 374 lcd.drawRect(70,6,10,10,1);
el13kz 2:635c58eb70fb 375 lcd.drawRect(70,21,10,10,0);
el13kz 5:e75537898d23 376 lcd.drawRect(70,37,10,10,0);//check box 3
el13kz 5:e75537898d23 377 lcd.printString("temperature",1,1);
el13kz 6:07133c44d3eb 378 lcd.printString("altitude",1,3);
el13kz 5:e75537898d23 379 lcd.printString("pressure",1,5);
el13kz 0:771a5148e8e7 380
el13kz 2:635c58eb70fb 381 lcd.printString(">",62,1);
el13kz 9:5ebf44c85f77 382 selectedOption2 = 1;
el13kz 6:07133c44d3eb 383 if (pushbutton1)
el13kz 4:47b0473fa81b 384 break;
el13kz 0:771a5148e8e7 385 wait(2);
el13kz 0:771a5148e8e7 386 lcd.clear();
el13kz 0:771a5148e8e7 387
el13kz 2:635c58eb70fb 388 lcd.drawRect(70,6,10,10,0);
el13kz 2:635c58eb70fb 389 lcd.drawRect(70,21,10,10,1);
el13kz 6:07133c44d3eb 390 lcd.drawRect(70,37,10,10,0);//check box 3
el13kz 5:e75537898d23 391 lcd.printString("temperature",1,1);
el13kz 5:e75537898d23 392 lcd.printString("pressure",1,5);
el13kz 5:e75537898d23 393
el13kz 4:47b0473fa81b 394 lcd.printString("altitude",1,3);
el13kz 2:635c58eb70fb 395 lcd.printString(">",62,3);
el13kz 9:5ebf44c85f77 396 selectedOption2 = 2;
el13kz 6:07133c44d3eb 397 if (pushbutton1)
el13kz 4:47b0473fa81b 398 break;
el13kz 4:47b0473fa81b 399 wait(2);
el13kz 4:47b0473fa81b 400 lcd.clear();
el13kz 0:771a5148e8e7 401
el13kz 5:e75537898d23 402 lcd.drawRect(70,6,10,10,0);
el13kz 5:e75537898d23 403 lcd.drawRect(70,21,10,10,0);
el13kz 5:e75537898d23 404 lcd.drawRect(70,37,10,10,1);//check box 3
el13kz 6:07133c44d3eb 405 lcd.printString("temperature",1,1);
el13kz 6:07133c44d3eb 406 lcd.printString("altitude",1,3);
el13kz 5:e75537898d23 407 lcd.printString("pressure",1,5);
el13kz 5:e75537898d23 408 lcd.printString(">",62,5);
el13kz 9:5ebf44c85f77 409 selectedOption2 = 3;
el13kz 6:07133c44d3eb 410 if (pushbutton1)
el13kz 4:47b0473fa81b 411 break;
el13kz 0:771a5148e8e7 412 wait(2);
el13kz 0:771a5148e8e7 413 lcd.clear();
el13kz 2:635c58eb70fb 414
el13kz 2:635c58eb70fb 415 }
el13kz 2:635c58eb70fb 416
el13kz 9:5ebf44c85f77 417 if(selectedOption2 == 1) {
el13kz 0:771a5148e8e7 418
el13kz 4:47b0473fa81b 419 pressure();
el13kz 2:635c58eb70fb 420 }
el13kz 2:635c58eb70fb 421
el13kz 9:5ebf44c85f77 422 if(selectedOption2 == 2) {
el13kz 2:635c58eb70fb 423
el13kz 4:47b0473fa81b 424 temperature();
el13kz 2:635c58eb70fb 425
el13kz 2:635c58eb70fb 426 }
el13kz 4:47b0473fa81b 427
el13kz 9:5ebf44c85f77 428 if(selectedOption2 == 3) {
el13kz 4:47b0473fa81b 429
el13kz 4:47b0473fa81b 430 altitude();
el13kz 4:47b0473fa81b 431 }
el13kz 4:47b0473fa81b 432
el13kz 4:47b0473fa81b 433
el13kz 0:771a5148e8e7 434 }
el13kz 0:771a5148e8e7 435
el13kz 0:771a5148e8e7 436 void introScreen()
el13kz 0:771a5148e8e7 437 {
el13kz 0:771a5148e8e7 438
el13kz 6:07133c44d3eb 439 lcd.printString("Welcome to",5,1);
el13kz 6:07133c44d3eb 440 lcd.printString("Keiarash's",5,2);
el13kz 6:07133c44d3eb 441 lcd.printString("Multi-Sensor",5,3);
el13kz 6:07133c44d3eb 442 Redled= 1.0;
el13kz 0:771a5148e8e7 443
el13kz 0:771a5148e8e7 444
el13kz 0:771a5148e8e7 445 }
el13kz 0:771a5148e8e7 446
el13kz 4:47b0473fa81b 447
el13kz 4:47b0473fa81b 448 void extrasScreen()
el13kz 6:07133c44d3eb 449 {
el13kz 6:07133c44d3eb 450 lcd.clear();
el13kz 6:07133c44d3eb 451 lcd.printString("Hold Button!",6,2);//select measure menu
el13kz 6:07133c44d3eb 452 wait(1);
el13kz 6:07133c44d3eb 453 lcd.clear();
el13kz 9:5ebf44c85f77 454 selectedOption3 = 0;
el13kz 4:47b0473fa81b 455
el13kz 4:47b0473fa81b 456 while(1) {
el13kz 4:47b0473fa81b 457
el13kz 4:47b0473fa81b 458 lcd.drawRect(70,6,10,10,1);
el13kz 4:47b0473fa81b 459 lcd.drawRect(70,21,10,10,0);
el13kz 4:47b0473fa81b 460
el13kz 4:47b0473fa81b 461 lcd.printString("check",1,1);
el13kz 4:47b0473fa81b 462 lcd.printString(">",62,1);
el13kz 9:5ebf44c85f77 463 selectedOption3 = 1;
el13kz 6:07133c44d3eb 464 if (pushbutton1)
el13kz 4:47b0473fa81b 465 break;
el13kz 4:47b0473fa81b 466 wait(2);
el13kz 4:47b0473fa81b 467 lcd.clear();
el13kz 4:47b0473fa81b 468
el13kz 4:47b0473fa81b 469 lcd.drawRect(70,6,10,10,0);
el13kz 4:47b0473fa81b 470 lcd.drawRect(70,21,10,10,1);
el13kz 4:47b0473fa81b 471 lcd.printString("go back",1,3);
el13kz 4:47b0473fa81b 472 lcd.printString(">",62,3);
el13kz 9:5ebf44c85f77 473 selectedOption3 = 2;
el13kz 6:07133c44d3eb 474 if (pushbutton1)
el13kz 4:47b0473fa81b 475 break;
el13kz 4:47b0473fa81b 476 wait(2);
el13kz 4:47b0473fa81b 477 lcd.clear();
el13kz 4:47b0473fa81b 478
el13kz 4:47b0473fa81b 479 }
el13kz 4:47b0473fa81b 480
el13kz 9:5ebf44c85f77 481 if(selectedOption3 == 1) {
el13kz 4:47b0473fa81b 482
el13kz 4:47b0473fa81b 483 lcd.clear();
el13kz 4:47b0473fa81b 484 }
el13kz 4:47b0473fa81b 485
el13kz 9:5ebf44c85f77 486 if(selectedOption3 == 2) {
el13kz 4:47b0473fa81b 487
el13kz 5:e75537898d23 488 check();
el13kz 7:c39d54bdff28 489 wait(0.5);
el13kz 4:47b0473fa81b 490
el13kz 4:47b0473fa81b 491 }
el13kz 4:47b0473fa81b 492 }
el13kz 4:47b0473fa81b 493
el13kz 4:47b0473fa81b 494
el13kz 4:47b0473fa81b 495
el13kz 0:771a5148e8e7 496 void mainScreen()
el13kz 0:771a5148e8e7 497 {
el13kz 7:c39d54bdff28 498 lcd.clear();
el13kz 6:07133c44d3eb 499 lcd.printString("Hold Button!",6,2);//select measure menu
el13kz 4:47b0473fa81b 500
el13kz 6:07133c44d3eb 501 wait(1);
el13kz 6:07133c44d3eb 502 lcd.clear();
el13kz 6:07133c44d3eb 503
el13kz 9:5ebf44c85f77 504 selectedOption4 = 0;
el13kz 0:771a5148e8e7 505
el13kz 4:47b0473fa81b 506 while(1) {//initialse pushbutton as 0
el13kz 6:07133c44d3eb 507
el13kz 2:635c58eb70fb 508 //check boxes-options to be selected
el13kz 2:635c58eb70fb 509 lcd.drawRect(70,6,10,10,1);//check box 1
el13kz 2:635c58eb70fb 510 lcd.drawRect(70,21,10,10,0);//check box 2
el13kz 2:635c58eb70fb 511 lcd.drawRect(70,37,10,10,0);//check box 3
el13kz 0:771a5148e8e7 512
el13kz 2:635c58eb70fb 513 //option titles-appropriate to check boxes
el13kz 4:47b0473fa81b 514 lcd.printString("extras",1,1);//select measure menu
el13kz 4:47b0473fa81b 515 lcd.printString("graph",1,3);//select settings menu
el13kz 4:47b0473fa81b 516 lcd.printString("measure",1,5);//select grpah plot
el13kz 2:635c58eb70fb 517 lcd.printString(">",62,1);//pointer
el13kz 9:5ebf44c85f77 518 selectedOption4 = 1;
el13kz 4:47b0473fa81b 519 if (pushbutton1)
el13kz 4:47b0473fa81b 520 break;
el13kz 0:771a5148e8e7 521
el13kz 0:771a5148e8e7 522 wait(2);
el13kz 0:771a5148e8e7 523 lcd.clear();
el13kz 0:771a5148e8e7 524
el13kz 0:771a5148e8e7 525 lcd.drawRect(70,6,10,10,0);
el13kz 0:771a5148e8e7 526 lcd.drawRect(70,21,10,10,1);
el13kz 0:771a5148e8e7 527 lcd.drawRect(70,37,10,10,0);
el13kz 0:771a5148e8e7 528
el13kz 0:771a5148e8e7 529
el13kz 4:47b0473fa81b 530 lcd.printString("extras",1,1);
el13kz 4:47b0473fa81b 531 lcd.printString("graph",1,3);
el13kz 4:47b0473fa81b 532 lcd.printString("measure",1,5);
el13kz 0:771a5148e8e7 533 lcd.printString(">",62,3);
el13kz 9:5ebf44c85f77 534 selectedOption4 = 2;
el13kz 6:07133c44d3eb 535 if (pushbutton1)
el13kz 4:47b0473fa81b 536 break;
el13kz 4:47b0473fa81b 537
el13kz 0:771a5148e8e7 538
el13kz 0:771a5148e8e7 539 wait(2);
el13kz 0:771a5148e8e7 540 lcd.clear();
el13kz 0:771a5148e8e7 541
el13kz 0:771a5148e8e7 542 lcd.drawRect(70,6,10,10,0);
el13kz 0:771a5148e8e7 543 lcd.drawRect(70,21,10,10,0);
el13kz 0:771a5148e8e7 544 lcd.drawRect(70,37,10,10,1);
el13kz 0:771a5148e8e7 545
el13kz 0:771a5148e8e7 546
el13kz 4:47b0473fa81b 547 lcd.printString("extras",1,1);
el13kz 4:47b0473fa81b 548 lcd.printString("graph",1,3);
el13kz 4:47b0473fa81b 549 lcd.printString("measure",1,5);
el13kz 0:771a5148e8e7 550 lcd.printString(">",62,5);
el13kz 9:5ebf44c85f77 551 selectedOption4 = 3;
el13kz 6:07133c44d3eb 552 if (pushbutton1)
el13kz 4:47b0473fa81b 553 break;
el13kz 4:47b0473fa81b 554
el13kz 0:771a5148e8e7 555
el13kz 0:771a5148e8e7 556 wait(2);
el13kz 0:771a5148e8e7 557 lcd.clear();
el13kz 0:771a5148e8e7 558
el13kz 0:771a5148e8e7 559
el13kz 0:771a5148e8e7 560 }
el13kz 2:635c58eb70fb 561
el13kz 9:5ebf44c85f77 562 if(selectedOption4 == 1) {
el13kz 2:635c58eb70fb 563
el13kz 4:47b0473fa81b 564 measurementsScreen();
el13kz 2:635c58eb70fb 565 }
el13kz 2:635c58eb70fb 566
el13kz 9:5ebf44c85f77 567 if(selectedOption4 == 2) {
el13kz 2:635c58eb70fb 568
el13kz 4:47b0473fa81b 569 extrasScreen();
el13kz 2:635c58eb70fb 570 }
el13kz 2:635c58eb70fb 571
el13kz 9:5ebf44c85f77 572 if(selectedOption4 == 3) {
el13kz 2:635c58eb70fb 573
el13kz 7:c39d54bdff28 574 graphScreen();
el13kz 2:635c58eb70fb 575 }
el13kz 0:771a5148e8e7 576 }
el13kz 0:771a5148e8e7 577
el13kz 0:771a5148e8e7 578
el13kz 0:771a5148e8e7 579
el13kz 0:771a5148e8e7 580
el13kz 0:771a5148e8e7 581
el13kz 0:771a5148e8e7 582
el13kz 0:771a5148e8e7 583
el13kz 2:635c58eb70fb 584
el13kz 2:635c58eb70fb 585
el13kz 6:07133c44d3eb 586
el13kz 2:635c58eb70fb 587
el13kz 2:635c58eb70fb 588 //main loop
el13kz 0:771a5148e8e7 589 int main()
el13kz 0:771a5148e8e7 590 {
el13kz 9:5ebf44c85f77 591 pushbutton1.mode(PullUp);//initial value 0
el13kz 0:771a5148e8e7 592 // initiliase barometer
el13kz 0:771a5148e8e7 593 bmp180.init();
el13kz 6:07133c44d3eb 594
el13kz 0:771a5148e8e7 595 lcd.init();
el13kz 0:771a5148e8e7 596 introScreen();
el13kz 7:c39d54bdff28 597 wait(3);
el13kz 2:635c58eb70fb 598 Redled =0;
el13kz 9:5ebf44c85f77 599
el13kz 6:07133c44d3eb 600
el13kz 9:5ebf44c85f77 601 while(1) {
el13kz 9:5ebf44c85f77 602
el13kz 9:5ebf44c85f77 603 lcd.clear();
el13kz 9:5ebf44c85f77 604 lcd.printString("main menu...",1,2);
el13kz 9:5ebf44c85f77 605 wait(2);
el13kz 9:5ebf44c85f77 606 mainScreen();
el13kz 9:5ebf44c85f77 607
el13kz 6:07133c44d3eb 608
el13kz 6:07133c44d3eb 609
el13kz 6:07133c44d3eb 610 }
el13kz 2:635c58eb70fb 611 }