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