Keiarash Zoughi's Multi-Sensor for weather detection.
Dependencies: BMP180 N5110 mbed
main.cpp@5:e75537898d23, 2015-05-07 (annotated)
- Committer:
- el13kz
- Date:
- Thu May 07 16:23:29 2015 +0000
- Revision:
- 5:e75537898d23
- Parent:
- 4:47b0473fa81b
- Child:
- 6:07133c44d3eb
refinements
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:771a5148e8e7 | 28 | int selectedOption = 0; |
el13kz | 0:771a5148e8e7 | 29 | int buttonPressed = 0; |
el13kz | 0:771a5148e8e7 | 30 | |
el13kz | 2:635c58eb70fb | 31 | //boundary conditions - screen |
el13kz | 2:635c58eb70fb | 32 | int cells[84][48]; |
el13kz | 2:635c58eb70fb | 33 | |
el13kz | 4:47b0473fa81b | 34 | |
el13kz | 4:47b0473fa81b | 35 | void check(){ |
el13kz | 4:47b0473fa81b | 36 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 37 | Redled.period(0.02); // set PWM period to 20ms |
el13kz | 4:47b0473fa81b | 38 | |
el13kz | 4:47b0473fa81b | 39 | Measurement measurement; // measurement structure declared in BMP180 class |
el13kz | 4:47b0473fa81b | 40 | |
el13kz | 4:47b0473fa81b | 41 | |
el13kz | 4:47b0473fa81b | 42 | // read values (T in Celsius and P in mb) and print over serial port |
el13kz | 4:47b0473fa81b | 43 | measurement = bmp180.readValues(); |
el13kz | 4:47b0473fa81b | 44 | serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); |
el13kz | 4:47b0473fa81b | 45 | |
el13kz | 4:47b0473fa81b | 46 | // so can display a string of a maximum 14 characters in length |
el13kz | 4:47b0473fa81b | 47 | // or create formatted strings - ensure they aren't more than 14 characters long |
el13kz | 4:47b0473fa81b | 48 | int temperature = measurement.temperature; |
el13kz | 4:47b0473fa81b | 49 | // display on screen |
el13kz | 4:47b0473fa81b | 50 | // |
el13kz | 4:47b0473fa81b | 51 | float pressure = measurement.pressure; // same idea with floats |
el13kz | 4:47b0473fa81b | 52 | |
el13kz | 4:47b0473fa81b | 53 | |
el13kz | 4:47b0473fa81b | 54 | |
el13kz | 4:47b0473fa81b | 55 | if(measurement.temperature > 30 ){ |
el13kz | 4:47b0473fa81b | 56 | |
el13kz | 4:47b0473fa81b | 57 | lcd.printString("temperature high!",1,1); |
el13kz | 4:47b0473fa81b | 58 | |
el13kz | 4:47b0473fa81b | 59 | Redled=1.0; |
el13kz | 4:47b0473fa81b | 60 | |
el13kz | 4:47b0473fa81b | 61 | wait(3); } |
el13kz | 4:47b0473fa81b | 62 | |
el13kz | 4:47b0473fa81b | 63 | if(measurement.temperature < 3){ |
el13kz | 4:47b0473fa81b | 64 | |
el13kz | 4:47b0473fa81b | 65 | lcd.printString("temperature low!",1,1); |
el13kz | 4:47b0473fa81b | 66 | |
el13kz | 4:47b0473fa81b | 67 | Redled= 1.0; |
el13kz | 4:47b0473fa81b | 68 | |
el13kz | 4:47b0473fa81b | 69 | wait(3); } |
el13kz | 4:47b0473fa81b | 70 | |
el13kz | 4:47b0473fa81b | 71 | else { lcd.printString("temperature ok!",1,1); |
el13kz | 4:47b0473fa81b | 72 | wait(3); |
el13kz | 4:47b0473fa81b | 73 | } |
el13kz | 4:47b0473fa81b | 74 | } |
el13kz | 4:47b0473fa81b | 75 | |
el13kz | 4:47b0473fa81b | 76 | |
el13kz | 4:47b0473fa81b | 77 | |
el13kz | 4:47b0473fa81b | 78 | |
el13kz | 4:47b0473fa81b | 79 | |
el13kz | 4:47b0473fa81b | 80 | |
el13kz | 4:47b0473fa81b | 81 | |
el13kz | 4:47b0473fa81b | 82 | |
el13kz | 2:635c58eb70fb | 83 | //shows pressure reading and temperature |
el13kz | 0:771a5148e8e7 | 84 | void measurement() |
el13kz | 4:47b0473fa81b | 85 | {lcd.clear(); |
el13kz | 4:47b0473fa81b | 86 | |
el13kz | 0:771a5148e8e7 | 87 | Measurement measurement; // measurement structure declared in BMP180 class |
el13kz | 0:771a5148e8e7 | 88 | while(1) { |
el13kz | 0:771a5148e8e7 | 89 | |
el13kz | 0:771a5148e8e7 | 90 | // read values (T in Celsius and P in mb) and print over serial port |
el13kz | 0:771a5148e8e7 | 91 | measurement = bmp180.readValues(); |
el13kz | 0:771a5148e8e7 | 92 | serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); |
el13kz | 0:771a5148e8e7 | 93 | |
el13kz | 0:771a5148e8e7 | 94 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) |
el13kz | 0:771a5148e8e7 | 95 | // so can display a string of a maximum 14 characters in length |
el13kz | 0:771a5148e8e7 | 96 | // or create formatted strings - ensure they aren't more than 14 characters long |
el13kz | 0:771a5148e8e7 | 97 | int temperature = measurement.temperature; |
el13kz | 0:771a5148e8e7 | 98 | int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer |
el13kz | 0:771a5148e8e7 | 99 | // it is important the format specifier ensures the length will fit in the buffer |
el13kz | 0:771a5148e8e7 | 100 | if (length <= 14) // if string will fit on display |
el13kz | 0:771a5148e8e7 | 101 | lcd.printString(buffer,0,1); // display on screen |
el13kz | 0:771a5148e8e7 | 102 | // |
el13kz | 0:771a5148e8e7 | 103 | float pressure = measurement.pressure; // same idea with floats |
el13kz | 0:771a5148e8e7 | 104 | length = sprintf(buffer,"P = %.2f mb",pressure); |
el13kz | 0:771a5148e8e7 | 105 | if (length <= 14) |
el13kz | 0:771a5148e8e7 | 106 | lcd.printString(buffer,0,2); |
el13kz | 0:771a5148e8e7 | 107 | } |
el13kz | 0:771a5148e8e7 | 108 | } |
el13kz | 0:771a5148e8e7 | 109 | |
el13kz | 4:47b0473fa81b | 110 | void temperature(){ |
el13kz | 4:47b0473fa81b | 111 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 112 | |
el13kz | 4:47b0473fa81b | 113 | Measurement measurement; // measurement structure declared in BMP180 class |
el13kz | 4:47b0473fa81b | 114 | while(1) { |
el13kz | 4:47b0473fa81b | 115 | |
el13kz | 4:47b0473fa81b | 116 | // read values (T in Celsius and P in mb) and print over serial port |
el13kz | 4:47b0473fa81b | 117 | measurement = bmp180.readValues(); |
el13kz | 4:47b0473fa81b | 118 | serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); |
el13kz | 4:47b0473fa81b | 119 | |
el13kz | 4:47b0473fa81b | 120 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) |
el13kz | 4:47b0473fa81b | 121 | // so can display a string of a maximum 14 characters in length |
el13kz | 4:47b0473fa81b | 122 | // or create formatted strings - ensure they aren't more than 14 characters long |
el13kz | 4:47b0473fa81b | 123 | int temperature = measurement.temperature; |
el13kz | 4:47b0473fa81b | 124 | int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer |
el13kz | 4:47b0473fa81b | 125 | // it is important the format specifier ensures the length will fit in the buffer |
el13kz | 4:47b0473fa81b | 126 | if (length <= 14) // if string will fit on display |
el13kz | 4:47b0473fa81b | 127 | lcd.printString(buffer,0,1); // |
el13kz | 4:47b0473fa81b | 128 | |
el13kz | 4:47b0473fa81b | 129 | } |
el13kz | 4:47b0473fa81b | 130 | } |
el13kz | 4:47b0473fa81b | 131 | |
el13kz | 4:47b0473fa81b | 132 | void pressure(){ |
el13kz | 4:47b0473fa81b | 133 | |
el13kz | 4:47b0473fa81b | 134 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 135 | |
el13kz | 4:47b0473fa81b | 136 | Measurement measurement; // measurement structure declared in BMP180 class |
el13kz | 4:47b0473fa81b | 137 | while(1) { |
el13kz | 4:47b0473fa81b | 138 | |
el13kz | 4:47b0473fa81b | 139 | // read values (T in Celsius and P in mb) and print over serial port |
el13kz | 4:47b0473fa81b | 140 | measurement = bmp180.readValues(); |
el13kz | 4:47b0473fa81b | 141 | serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); |
el13kz | 4:47b0473fa81b | 142 | |
el13kz | 4:47b0473fa81b | 143 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) |
el13kz | 4:47b0473fa81b | 144 | // so can display a string of a maximum 14 characters in length |
el13kz | 4:47b0473fa81b | 145 | // or create formatted strings - ensure they aren't more than 14 characters long |
el13kz | 4:47b0473fa81b | 146 | |
el13kz | 4:47b0473fa81b | 147 | // |
el13kz | 4:47b0473fa81b | 148 | float pressure = measurement.pressure; // same idea with floats |
el13kz | 5:e75537898d23 | 149 | int length = sprintf(buffer,"P = %.2f mb",pressure); |
el13kz | 4:47b0473fa81b | 150 | if (length <= 14) |
el13kz | 4:47b0473fa81b | 151 | lcd.printString(buffer,0,2); |
el13kz | 5:e75537898d23 | 152 | } |
el13kz | 5:e75537898d23 | 153 | } |
el13kz | 4:47b0473fa81b | 154 | |
el13kz | 4:47b0473fa81b | 155 | |
el13kz | 4:47b0473fa81b | 156 | |
el13kz | 4:47b0473fa81b | 157 | void altitude(){ // creating a new reading from the current ones, this appoximates the altitude in metres. |
el13kz | 4:47b0473fa81b | 158 | |
el13kz | 4:47b0473fa81b | 159 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 160 | |
el13kz | 4:47b0473fa81b | 161 | Measurement measurement; // measurement structure declared in BMP180 class |
el13kz | 4:47b0473fa81b | 162 | |
el13kz | 4:47b0473fa81b | 163 | while(1){ |
el13kz | 4:47b0473fa81b | 164 | // read values (T in Celsius and P in mb) and print over serial port |
el13kz | 4:47b0473fa81b | 165 | measurement = bmp180.readValues(); |
el13kz | 4:47b0473fa81b | 166 | char buffer[14]; |
el13kz | 4:47b0473fa81b | 167 | int temperature = measurement.temperature; |
el13kz | 4:47b0473fa81b | 168 | float pressure = measurement.pressure; // same idea with floats |
el13kz | 4:47b0473fa81b | 169 | |
el13kz | 4:47b0473fa81b | 170 | float altitude = -(log(pressure/1013.25)*1.38e-23*temperature)/(9.81*28.95); |
el13kz | 4:47b0473fa81b | 171 | serial.printf("A = %.2f m",altitude); |
el13kz | 4:47b0473fa81b | 172 | int length = sprintf(buffer,"A = %.2f m",altitude); // print formatted data to buffer |
el13kz | 4:47b0473fa81b | 173 | // it is important the format specifier ensures the length will fit in the buffer |
el13kz | 4:47b0473fa81b | 174 | if (length <= 14) // if string wi |
el13kz | 4:47b0473fa81b | 175 | lcd.printString(buffer,0,1); // display on screen |
el13kz | 4:47b0473fa81b | 176 | |
el13kz | 4:47b0473fa81b | 177 | |
el13kz | 4:47b0473fa81b | 178 | |
el13kz | 4:47b0473fa81b | 179 | |
el13kz | 4:47b0473fa81b | 180 | } |
el13kz | 4:47b0473fa81b | 181 | |
el13kz | 4:47b0473fa81b | 182 | } |
el13kz | 2:635c58eb70fb | 183 | //pushbutton - 0 |
el13kz | 0:771a5148e8e7 | 184 | |
el13kz | 2:635c58eb70fb | 185 | //plots graph of temperature point by point |
el13kz | 0:771a5148e8e7 | 186 | void graph() |
el13kz | 4:47b0473fa81b | 187 | {lcd.clear(); |
el13kz | 4:47b0473fa81b | 188 | |
el13kz | 0:771a5148e8e7 | 189 | Measurement measurement; // measurement structure declared in BMP180 class |
el13kz | 0:771a5148e8e7 | 190 | int i = 0; |
el13kz | 0:771a5148e8e7 | 191 | float graph[84]= {0}; |
el13kz | 0:771a5148e8e7 | 192 | while(1) { |
el13kz | 0:771a5148e8e7 | 193 | |
el13kz | 0:771a5148e8e7 | 194 | // read values (T in Celsius and P in mb) and print over serial port |
el13kz | 0:771a5148e8e7 | 195 | measurement = bmp180.readValues(); |
el13kz | 0:771a5148e8e7 | 196 | //serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure); |
el13kz | 0:771a5148e8e7 | 197 | |
el13kz | 0:771a5148e8e7 | 198 | // so can display a string of a maximum 14 characters in length |
el13kz | 0:771a5148e8e7 | 199 | // or create formatted strings - ensure they aren't more than 14 characters long |
el13kz | 0:771a5148e8e7 | 200 | int temperature = measurement.temperature; |
el13kz | 0:771a5148e8e7 | 201 | // int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer |
el13kz | 0:771a5148e8e7 | 202 | // it is important the format specifier ensures the length will fit in the buffer |
el13kz | 0:771a5148e8e7 | 203 | // if (length <= 14) // if string will fit on display |
el13kz | 0:771a5148e8e7 | 204 | // lcd.printString(buffer,0,1); // display on screen |
el13kz | 0:771a5148e8e7 | 205 | // |
el13kz | 0:771a5148e8e7 | 206 | // float pressure = measurement.pressure; // same idea with floats |
el13kz | 0:771a5148e8e7 | 207 | // length = sprintf(buffer,"P = %.2f mb",pressure); |
el13kz | 0:771a5148e8e7 | 208 | // if (length <= 14) |
el13kz | 0:771a5148e8e7 | 209 | // lcd.printString(buffer,0,2); |
el13kz | 0:771a5148e8e7 | 210 | |
el13kz | 0:771a5148e8e7 | 211 | graph[i]= temperature ; |
el13kz | 0:771a5148e8e7 | 212 | lcd.plotArray(graph); |
el13kz | 0:771a5148e8e7 | 213 | wait(0.1); // short delay until next reading |
el13kz | 0:771a5148e8e7 | 214 | i++; |
el13kz | 0:771a5148e8e7 | 215 | if (i>83) { |
el13kz | 0:771a5148e8e7 | 216 | i=0; |
el13kz | 0:771a5148e8e7 | 217 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 218 | } |
el13kz | 0:771a5148e8e7 | 219 | } |
el13kz | 0:771a5148e8e7 | 220 | } |
el13kz | 0:771a5148e8e7 | 221 | |
el13kz | 4:47b0473fa81b | 222 | |
el13kz | 4:47b0473fa81b | 223 | |
el13kz | 4:47b0473fa81b | 224 | |
el13kz | 4:47b0473fa81b | 225 | |
el13kz | 4:47b0473fa81b | 226 | void measurementsScreen() |
el13kz | 4:47b0473fa81b | 227 | {lcd.clear(); |
el13kz | 4:47b0473fa81b | 228 | lcd.printString("Hold Button!",1,1);//select measure menu |
el13kz | 4:47b0473fa81b | 229 | wait(1); |
el13kz | 4:47b0473fa81b | 230 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 231 | selectedOption = 0; |
el13kz | 0:771a5148e8e7 | 232 | |
el13kz | 4:47b0473fa81b | 233 | while(1) { |
el13kz | 0:771a5148e8e7 | 234 | |
el13kz | 2:635c58eb70fb | 235 | lcd.drawRect(70,6,10,10,1); |
el13kz | 2:635c58eb70fb | 236 | lcd.drawRect(70,21,10,10,0); |
el13kz | 5:e75537898d23 | 237 | lcd.drawRect(70,37,10,10,0);//check box 3 |
el13kz | 5:e75537898d23 | 238 | lcd.printString("temperature",1,1); |
el13kz | 5:e75537898d23 | 239 | lcd.printString("altitude",1,3); |
el13kz | 5:e75537898d23 | 240 | lcd.printString("pressure",1,5); |
el13kz | 0:771a5148e8e7 | 241 | |
el13kz | 2:635c58eb70fb | 242 | lcd.printString(">",62,1); |
el13kz | 2:635c58eb70fb | 243 | selectedOption = 1; |
el13kz | 4:47b0473fa81b | 244 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 245 | break; |
el13kz | 0:771a5148e8e7 | 246 | wait(2); |
el13kz | 0:771a5148e8e7 | 247 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 248 | |
el13kz | 2:635c58eb70fb | 249 | lcd.drawRect(70,6,10,10,0); |
el13kz | 2:635c58eb70fb | 250 | lcd.drawRect(70,21,10,10,1); |
el13kz | 5:e75537898d23 | 251 | lcd.drawRect(70,37,10,10,0);//check box 3 |
el13kz | 5:e75537898d23 | 252 | lcd.printString("temperature",1,1); |
el13kz | 5:e75537898d23 | 253 | lcd.printString("pressure",1,5); |
el13kz | 5:e75537898d23 | 254 | |
el13kz | 4:47b0473fa81b | 255 | lcd.printString("altitude",1,3); |
el13kz | 2:635c58eb70fb | 256 | lcd.printString(">",62,3); |
el13kz | 2:635c58eb70fb | 257 | selectedOption = 2; |
el13kz | 4:47b0473fa81b | 258 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 259 | break; |
el13kz | 4:47b0473fa81b | 260 | wait(2); |
el13kz | 4:47b0473fa81b | 261 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 262 | |
el13kz | 5:e75537898d23 | 263 | lcd.drawRect(70,6,10,10,0); |
el13kz | 5:e75537898d23 | 264 | lcd.drawRect(70,21,10,10,0); |
el13kz | 5:e75537898d23 | 265 | lcd.drawRect(70,37,10,10,1);//check box 3 |
el13kz | 5:e75537898d23 | 266 | lcd.printString("temperature",1,1); |
el13kz | 5:e75537898d23 | 267 | lcd.printString("altitude",1,3); |
el13kz | 5:e75537898d23 | 268 | lcd.printString("pressure",1,5); |
el13kz | 5:e75537898d23 | 269 | lcd.printString(">",62,5); |
el13kz | 5:e75537898d23 | 270 | selectedOption = 3; |
el13kz | 4:47b0473fa81b | 271 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 272 | break; |
el13kz | 0:771a5148e8e7 | 273 | wait(2); |
el13kz | 0:771a5148e8e7 | 274 | lcd.clear(); |
el13kz | 2:635c58eb70fb | 275 | |
el13kz | 2:635c58eb70fb | 276 | } |
el13kz | 2:635c58eb70fb | 277 | |
el13kz | 2:635c58eb70fb | 278 | if(selectedOption == 1) { |
el13kz | 0:771a5148e8e7 | 279 | |
el13kz | 4:47b0473fa81b | 280 | pressure(); |
el13kz | 2:635c58eb70fb | 281 | } |
el13kz | 2:635c58eb70fb | 282 | |
el13kz | 2:635c58eb70fb | 283 | if(selectedOption == 2) { |
el13kz | 2:635c58eb70fb | 284 | |
el13kz | 4:47b0473fa81b | 285 | temperature(); |
el13kz | 2:635c58eb70fb | 286 | |
el13kz | 2:635c58eb70fb | 287 | } |
el13kz | 4:47b0473fa81b | 288 | |
el13kz | 4:47b0473fa81b | 289 | if(selectedOption == 3) { |
el13kz | 4:47b0473fa81b | 290 | |
el13kz | 4:47b0473fa81b | 291 | altitude(); |
el13kz | 4:47b0473fa81b | 292 | } |
el13kz | 4:47b0473fa81b | 293 | |
el13kz | 4:47b0473fa81b | 294 | |
el13kz | 0:771a5148e8e7 | 295 | } |
el13kz | 0:771a5148e8e7 | 296 | |
el13kz | 0:771a5148e8e7 | 297 | void introScreen() |
el13kz | 0:771a5148e8e7 | 298 | { |
el13kz | 0:771a5148e8e7 | 299 | |
el13kz | 0:771a5148e8e7 | 300 | lcd.printString("Welcome to",15,1); |
el13kz | 0:771a5148e8e7 | 301 | lcd.printString("Keiarash's",20,2); |
el13kz | 0:771a5148e8e7 | 302 | lcd.printString("Multi-Sensor",6,3); |
el13kz | 2:635c58eb70fb | 303 | Redled= 1.0; |
el13kz | 0:771a5148e8e7 | 304 | |
el13kz | 0:771a5148e8e7 | 305 | |
el13kz | 0:771a5148e8e7 | 306 | } |
el13kz | 0:771a5148e8e7 | 307 | |
el13kz | 4:47b0473fa81b | 308 | |
el13kz | 4:47b0473fa81b | 309 | void extrasScreen() |
el13kz | 4:47b0473fa81b | 310 | {lcd.clear(); |
el13kz | 4:47b0473fa81b | 311 | lcd.printString("Hold Button!",1,1);//select measure menu |
el13kz | 4:47b0473fa81b | 312 | wait(1); |
el13kz | 4:47b0473fa81b | 313 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 314 | selectedOption = 0; |
el13kz | 4:47b0473fa81b | 315 | |
el13kz | 4:47b0473fa81b | 316 | while(1) { |
el13kz | 4:47b0473fa81b | 317 | |
el13kz | 4:47b0473fa81b | 318 | lcd.drawRect(70,6,10,10,1); |
el13kz | 4:47b0473fa81b | 319 | lcd.drawRect(70,21,10,10,0); |
el13kz | 4:47b0473fa81b | 320 | |
el13kz | 4:47b0473fa81b | 321 | lcd.printString("check",1,1); |
el13kz | 4:47b0473fa81b | 322 | lcd.printString(">",62,1); |
el13kz | 4:47b0473fa81b | 323 | selectedOption = 1; |
el13kz | 4:47b0473fa81b | 324 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 325 | break; |
el13kz | 4:47b0473fa81b | 326 | wait(2); |
el13kz | 4:47b0473fa81b | 327 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 328 | |
el13kz | 4:47b0473fa81b | 329 | lcd.drawRect(70,6,10,10,0); |
el13kz | 4:47b0473fa81b | 330 | lcd.drawRect(70,21,10,10,1); |
el13kz | 4:47b0473fa81b | 331 | lcd.printString("go back",1,3); |
el13kz | 4:47b0473fa81b | 332 | lcd.printString(">",62,3); |
el13kz | 4:47b0473fa81b | 333 | selectedOption = 2; |
el13kz | 4:47b0473fa81b | 334 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 335 | break; |
el13kz | 4:47b0473fa81b | 336 | wait(2); |
el13kz | 4:47b0473fa81b | 337 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 338 | |
el13kz | 4:47b0473fa81b | 339 | } |
el13kz | 4:47b0473fa81b | 340 | |
el13kz | 4:47b0473fa81b | 341 | if(selectedOption == 1) { |
el13kz | 4:47b0473fa81b | 342 | |
el13kz | 4:47b0473fa81b | 343 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 344 | } |
el13kz | 4:47b0473fa81b | 345 | |
el13kz | 4:47b0473fa81b | 346 | if(selectedOption == 2) { |
el13kz | 4:47b0473fa81b | 347 | |
el13kz | 5:e75537898d23 | 348 | check(); |
el13kz | 4:47b0473fa81b | 349 | |
el13kz | 4:47b0473fa81b | 350 | } |
el13kz | 4:47b0473fa81b | 351 | } |
el13kz | 4:47b0473fa81b | 352 | |
el13kz | 4:47b0473fa81b | 353 | |
el13kz | 4:47b0473fa81b | 354 | |
el13kz | 0:771a5148e8e7 | 355 | void mainScreen() |
el13kz | 0:771a5148e8e7 | 356 | { |
el13kz | 4:47b0473fa81b | 357 | |
el13kz | 4:47b0473fa81b | 358 | lcd.printString("Hold Button!",1,1);//select measure menu |
el13kz | 4:47b0473fa81b | 359 | |
el13kz | 4:47b0473fa81b | 360 | wait(1); |
el13kz | 4:47b0473fa81b | 361 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 362 | |
el13kz | 0:771a5148e8e7 | 363 | selectedOption = 0; |
el13kz | 0:771a5148e8e7 | 364 | |
el13kz | 4:47b0473fa81b | 365 | while(1) {//initialse pushbutton as 0 |
el13kz | 2:635c58eb70fb | 366 | |
el13kz | 2:635c58eb70fb | 367 | //check boxes-options to be selected |
el13kz | 2:635c58eb70fb | 368 | lcd.drawRect(70,6,10,10,1);//check box 1 |
el13kz | 2:635c58eb70fb | 369 | lcd.drawRect(70,21,10,10,0);//check box 2 |
el13kz | 2:635c58eb70fb | 370 | lcd.drawRect(70,37,10,10,0);//check box 3 |
el13kz | 0:771a5148e8e7 | 371 | |
el13kz | 2:635c58eb70fb | 372 | //option titles-appropriate to check boxes |
el13kz | 4:47b0473fa81b | 373 | lcd.printString("extras",1,1);//select measure menu |
el13kz | 4:47b0473fa81b | 374 | lcd.printString("graph",1,3);//select settings menu |
el13kz | 4:47b0473fa81b | 375 | lcd.printString("measure",1,5);//select grpah plot |
el13kz | 2:635c58eb70fb | 376 | lcd.printString(">",62,1);//pointer |
el13kz | 0:771a5148e8e7 | 377 | selectedOption = 1; |
el13kz | 4:47b0473fa81b | 378 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 379 | break; |
el13kz | 0:771a5148e8e7 | 380 | |
el13kz | 0:771a5148e8e7 | 381 | wait(2); |
el13kz | 0:771a5148e8e7 | 382 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 383 | |
el13kz | 0:771a5148e8e7 | 384 | lcd.drawRect(70,6,10,10,0); |
el13kz | 0:771a5148e8e7 | 385 | lcd.drawRect(70,21,10,10,1); |
el13kz | 0:771a5148e8e7 | 386 | lcd.drawRect(70,37,10,10,0); |
el13kz | 0:771a5148e8e7 | 387 | |
el13kz | 0:771a5148e8e7 | 388 | |
el13kz | 4:47b0473fa81b | 389 | lcd.printString("extras",1,1); |
el13kz | 4:47b0473fa81b | 390 | lcd.printString("graph",1,3); |
el13kz | 4:47b0473fa81b | 391 | lcd.printString("measure",1,5); |
el13kz | 0:771a5148e8e7 | 392 | lcd.printString(">",62,3); |
el13kz | 0:771a5148e8e7 | 393 | selectedOption = 2; |
el13kz | 4:47b0473fa81b | 394 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 395 | break; |
el13kz | 4:47b0473fa81b | 396 | |
el13kz | 0:771a5148e8e7 | 397 | |
el13kz | 0:771a5148e8e7 | 398 | wait(2); |
el13kz | 0:771a5148e8e7 | 399 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 400 | |
el13kz | 0:771a5148e8e7 | 401 | lcd.drawRect(70,6,10,10,0); |
el13kz | 0:771a5148e8e7 | 402 | lcd.drawRect(70,21,10,10,0); |
el13kz | 0:771a5148e8e7 | 403 | lcd.drawRect(70,37,10,10,1); |
el13kz | 0:771a5148e8e7 | 404 | |
el13kz | 0:771a5148e8e7 | 405 | |
el13kz | 4:47b0473fa81b | 406 | lcd.printString("extras",1,1); |
el13kz | 4:47b0473fa81b | 407 | lcd.printString("graph",1,3); |
el13kz | 4:47b0473fa81b | 408 | lcd.printString("measure",1,5); |
el13kz | 0:771a5148e8e7 | 409 | lcd.printString(">",62,5); |
el13kz | 0:771a5148e8e7 | 410 | selectedOption = 3; |
el13kz | 4:47b0473fa81b | 411 | if (pushbutton1) |
el13kz | 4:47b0473fa81b | 412 | break; |
el13kz | 4:47b0473fa81b | 413 | |
el13kz | 0:771a5148e8e7 | 414 | |
el13kz | 0:771a5148e8e7 | 415 | wait(2); |
el13kz | 0:771a5148e8e7 | 416 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 417 | |
el13kz | 0:771a5148e8e7 | 418 | |
el13kz | 0:771a5148e8e7 | 419 | } |
el13kz | 2:635c58eb70fb | 420 | |
el13kz | 2:635c58eb70fb | 421 | if(selectedOption == 1) { |
el13kz | 2:635c58eb70fb | 422 | |
el13kz | 4:47b0473fa81b | 423 | measurementsScreen(); |
el13kz | 2:635c58eb70fb | 424 | } |
el13kz | 2:635c58eb70fb | 425 | |
el13kz | 2:635c58eb70fb | 426 | if(selectedOption == 2) { |
el13kz | 2:635c58eb70fb | 427 | |
el13kz | 4:47b0473fa81b | 428 | extrasScreen(); |
el13kz | 2:635c58eb70fb | 429 | } |
el13kz | 2:635c58eb70fb | 430 | |
el13kz | 2:635c58eb70fb | 431 | if(selectedOption == 3) { |
el13kz | 2:635c58eb70fb | 432 | |
el13kz | 2:635c58eb70fb | 433 | graph(); |
el13kz | 2:635c58eb70fb | 434 | } |
el13kz | 0:771a5148e8e7 | 435 | } |
el13kz | 0:771a5148e8e7 | 436 | |
el13kz | 0:771a5148e8e7 | 437 | |
el13kz | 0:771a5148e8e7 | 438 | |
el13kz | 0:771a5148e8e7 | 439 | |
el13kz | 0:771a5148e8e7 | 440 | |
el13kz | 0:771a5148e8e7 | 441 | |
el13kz | 0:771a5148e8e7 | 442 | |
el13kz | 2:635c58eb70fb | 443 | |
el13kz | 2:635c58eb70fb | 444 | |
el13kz | 4:47b0473fa81b | 445 | |
el13kz | 2:635c58eb70fb | 446 | |
el13kz | 2:635c58eb70fb | 447 | //main loop |
el13kz | 0:771a5148e8e7 | 448 | int main() |
el13kz | 0:771a5148e8e7 | 449 | { |
el13kz | 2:635c58eb70fb | 450 | pushbutton1.mode(PullUp);//initial value 0 |
el13kz | 0:771a5148e8e7 | 451 | // initiliase barometer |
el13kz | 0:771a5148e8e7 | 452 | bmp180.init(); |
el13kz | 2:635c58eb70fb | 453 | |
el13kz | 0:771a5148e8e7 | 454 | lcd.init(); |
el13kz | 0:771a5148e8e7 | 455 | introScreen(); |
el13kz | 0:771a5148e8e7 | 456 | wait(3); |
el13kz | 2:635c58eb70fb | 457 | Redled =0; |
el13kz | 0:771a5148e8e7 | 458 | lcd.clear(); |
el13kz | 0:771a5148e8e7 | 459 | mainScreen(); |
el13kz | 0:771a5148e8e7 | 460 | |
el13kz | 2:635c58eb70fb | 461 | while(1) { |
el13kz | 4:47b0473fa81b | 462 | introScreen(); |
el13kz | 4:47b0473fa81b | 463 | wait(3); |
el13kz | 4:47b0473fa81b | 464 | Redled =0; |
el13kz | 4:47b0473fa81b | 465 | lcd.clear(); |
el13kz | 4:47b0473fa81b | 466 | mainScreen(); |
el13kz | 4:47b0473fa81b | 467 | |
el13kz | 4:47b0473fa81b | 468 | |
el13kz | 4:47b0473fa81b | 469 | |
el13kz | 2:635c58eb70fb | 470 | } |
el13kz | 2:635c58eb70fb | 471 | } |