A Weather station designed to read the values of temperature and pressure from the sensor (BMP180), data displayed via a nokia N5110 display.

Dependencies:   BMP180 N5110 PowerControl mbed

Committer:
amiraseman
Date:
Sat May 09 15:38:36 2015 +0000
Revision:
25:fa65a9cc78f0
Parent:
24:51cbed3fbf5c
Child:
26:c0d8d2f68406
debugged the alarms menu;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amiraseman 23:a0ce9fa869c2 1 /**
amiraseman 23:a0ce9fa869c2 2 @file Barometer.cpp
amiraseman 23:a0ce9fa869c2 3
amiraseman 23:a0ce9fa869c2 4 @brief Member functions implementations
amiraseman 23:a0ce9fa869c2 5
amiraseman 23:a0ce9fa869c2 6 */
amiraseman 23:a0ce9fa869c2 7 #include "mbed.h"
amiraseman 23:a0ce9fa869c2 8 #include "Barometer.h"
amiraseman 23:a0ce9fa869c2 9
amiraseman 23:a0ce9fa869c2 10
amiraseman 23:a0ce9fa869c2 11 ///
amiraseman 23:a0ce9fa869c2 12 void button1Pressed() //ISR to subtract 1 from the value of choice when the first button is pressed
amiraseman 23:a0ce9fa869c2 13 {
amiraseman 23:a0ce9fa869c2 14 if (debounce.read_ms()>200) // only allow if debounce timer
amiraseman 23:a0ce9fa869c2 15 button1Flag=1; // has passed 200 ms
amiraseman 23:a0ce9fa869c2 16 debounce.reset(); // restart timer when the toggle is performed
amiraseman 23:a0ce9fa869c2 17 }
amiraseman 23:a0ce9fa869c2 18
amiraseman 23:a0ce9fa869c2 19
amiraseman 23:a0ce9fa869c2 20 ///
amiraseman 23:a0ce9fa869c2 21 void button2Pressed() //ISR to add 1 to the value of the choice when the second button is pressed
amiraseman 23:a0ce9fa869c2 22 {
amiraseman 23:a0ce9fa869c2 23 if (debounce.read_ms()>200) // only allow if debounce timer
amiraseman 23:a0ce9fa869c2 24 button2Flag=1; // has passed 200 ms
amiraseman 23:a0ce9fa869c2 25 debounce.reset(); // restart timer when the toggle is performed
amiraseman 23:a0ce9fa869c2 26 }
amiraseman 23:a0ce9fa869c2 27
amiraseman 23:a0ce9fa869c2 28
amiraseman 23:a0ce9fa869c2 29 ///
amiraseman 23:a0ce9fa869c2 30 void button3Pressed()
amiraseman 23:a0ce9fa869c2 31 {
amiraseman 23:a0ce9fa869c2 32 if (debounce.read_ms()>200) // only allow if debounce timer
amiraseman 23:a0ce9fa869c2 33 button3Flag=1; // has passed 200 ms
amiraseman 23:a0ce9fa869c2 34 debounce.reset(); // restart timer when the toggle is performed
amiraseman 23:a0ce9fa869c2 35 }
amiraseman 23:a0ce9fa869c2 36
amiraseman 23:a0ce9fa869c2 37
amiraseman 23:a0ce9fa869c2 38 ///
amiraseman 23:a0ce9fa869c2 39 void button4Pressed()
amiraseman 23:a0ce9fa869c2 40 {
amiraseman 23:a0ce9fa869c2 41 if (debounce.read_ms()>200) // only allow if debounce timer
amiraseman 23:a0ce9fa869c2 42 button4Flag=1; // has passed 200 ms
amiraseman 23:a0ce9fa869c2 43 debounce.reset(); // restart timer when the toggle is performed
amiraseman 23:a0ce9fa869c2 44 }
amiraseman 23:a0ce9fa869c2 45
amiraseman 23:a0ce9fa869c2 46
amiraseman 23:a0ce9fa869c2 47
amiraseman 23:a0ce9fa869c2 48 /// ISR called by the timer to set the timer flag to 1 (flag is used to update the values of pressure and temperature every second for the live data function)
amiraseman 23:a0ce9fa869c2 49 void timerExpired()
amiraseman 23:a0ce9fa869c2 50 {
amiraseman 23:a0ce9fa869c2 51 yellowLED = 0;
amiraseman 23:a0ce9fa869c2 52 timerFlag=1;
amiraseman 23:a0ce9fa869c2 53
amiraseman 23:a0ce9fa869c2 54 }
amiraseman 23:a0ce9fa869c2 55
amiraseman 23:a0ce9fa869c2 56
amiraseman 23:a0ce9fa869c2 57 ///An ISR called by data logger timer to set the dataLoggerFlag to 1
amiraseman 23:a0ce9fa869c2 58 void dataLoggerTimerExpired ()
amiraseman 23:a0ce9fa869c2 59 {
amiraseman 23:a0ce9fa869c2 60 yellowLED = 0;
amiraseman 23:a0ce9fa869c2 61 dataLoggerFlag = 1 ;
amiraseman 23:a0ce9fa869c2 62
amiraseman 23:a0ce9fa869c2 63 }
amiraseman 23:a0ce9fa869c2 64
amiraseman 23:a0ce9fa869c2 65
amiraseman 23:a0ce9fa869c2 66 /// open a local file and print the recieved char arrays in the stream
amiraseman 23:a0ce9fa869c2 67 void saveToFile(char *data,char *data1,char *data2,char *data3)
amiraseman 23:a0ce9fa869c2 68 {
amiraseman 23:a0ce9fa869c2 69 FILE* pFile = fopen("/local/textfile.csv","w"); // open file access
amiraseman 23:a0ce9fa869c2 70 fprintf (pFile, "%s\n%s\n%s\n%s", data,data1,data2,data3);
amiraseman 23:a0ce9fa869c2 71 fclose (pFile);
amiraseman 23:a0ce9fa869c2 72 }
amiraseman 23:a0ce9fa869c2 73
amiraseman 23:a0ce9fa869c2 74
amiraseman 23:a0ce9fa869c2 75 /// Gets the current time and stores them in bufferTime and bufferDate
amiraseman 23:a0ce9fa869c2 76 void updateTime()
amiraseman 23:a0ce9fa869c2 77 {
amiraseman 23:a0ce9fa869c2 78 time_t seconds = time(NULL); // get current time
amiraseman 23:a0ce9fa869c2 79 // format time into a string (time and date)
amiraseman 23:a0ce9fa869c2 80 currentTime = seconds ; // sets the current time to an integer for alarm clock check
amiraseman 23:a0ce9fa869c2 81 //serial.printf("current time :%i \n",currentTime);
amiraseman 23:a0ce9fa869c2 82 //serial.printf("Unix date :%i \n",UNIXdate);
amiraseman 23:a0ce9fa869c2 83 strftime(bufferTime, 14 , "%H:%M", localtime(&seconds));
amiraseman 23:a0ce9fa869c2 84 strftime(bufferDate, 14 , "%d/%m/%y", localtime(&seconds));
amiraseman 23:a0ce9fa869c2 85 }
amiraseman 23:a0ce9fa869c2 86
amiraseman 23:a0ce9fa869c2 87
amiraseman 23:a0ce9fa869c2 88 /// Displays the screen buffers on the lcd
amiraseman 23:a0ce9fa869c2 89 void display()
amiraseman 23:a0ce9fa869c2 90 {
amiraseman 23:a0ce9fa869c2 91 lcd.clear();
amiraseman 23:a0ce9fa869c2 92 lcd.printString(buffer0,0,0);
amiraseman 23:a0ce9fa869c2 93 lcd.printString(buffer1,0,1);
amiraseman 23:a0ce9fa869c2 94 lcd.printString(buffer2,0,2);
amiraseman 23:a0ce9fa869c2 95 lcd.printString(buffer3,0,3);
amiraseman 23:a0ce9fa869c2 96 lcd.printString(buffer4,0,4);
amiraseman 23:a0ce9fa869c2 97 lcd.printString(buffer5,0,5);
amiraseman 23:a0ce9fa869c2 98 wait(0.1);
amiraseman 23:a0ce9fa869c2 99
amiraseman 23:a0ce9fa869c2 100 }
amiraseman 23:a0ce9fa869c2 101
amiraseman 23:a0ce9fa869c2 102
amiraseman 23:a0ce9fa869c2 103
amiraseman 23:a0ce9fa869c2 104 ///Imports the data and saves them to the bufferss
amiraseman 23:a0ce9fa869c2 105 void readData()
amiraseman 23:a0ce9fa869c2 106 {
amiraseman 23:a0ce9fa869c2 107
amiraseman 23:a0ce9fa869c2 108 Measurement measurement; // measurement structure declared in BMP180 class
amiraseman 23:a0ce9fa869c2 109
amiraseman 23:a0ce9fa869c2 110 measurement = bmp180.readValues();
amiraseman 23:a0ce9fa869c2 111 // serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
amiraseman 23:a0ce9fa869c2 112
amiraseman 23:a0ce9fa869c2 113
amiraseman 23:a0ce9fa869c2 114 if (unitFlag==1 || unitFlag==2 ) { //c
amiraseman 23:a0ce9fa869c2 115
amiraseman 23:a0ce9fa869c2 116 temperature = measurement.temperature;
amiraseman 23:a0ce9fa869c2 117 int length = sprintf(bufferT,"%0.1f",temperature); // print formatted data to buffer
amiraseman 23:a0ce9fa869c2 118 // it is important the format specifier ensures the length will fit in the buffer
amiraseman 23:a0ce9fa869c2 119 }
amiraseman 23:a0ce9fa869c2 120 if (unitFlag==3 || unitFlag==4 ) {//f
amiraseman 23:a0ce9fa869c2 121 temperature =( measurement.temperature*(9/5))+32;
amiraseman 23:a0ce9fa869c2 122 int length = sprintf(bufferT,"%0.1f",temperature); // print formatted data to buffer
amiraseman 23:a0ce9fa869c2 123 // it is important the format specifier ensures the length will fit in the buffer
amiraseman 23:a0ce9fa869c2 124 }
amiraseman 23:a0ce9fa869c2 125
amiraseman 23:a0ce9fa869c2 126
amiraseman 23:a0ce9fa869c2 127
amiraseman 23:a0ce9fa869c2 128
amiraseman 23:a0ce9fa869c2 129 if (unitFlag==1 || unitFlag==3 ) {//mb
amiraseman 23:a0ce9fa869c2 130 pressure = measurement.pressure; // same idea with float
amiraseman 23:a0ce9fa869c2 131 int length = sprintf(bufferP,"%.2f",pressure); // print formatted data to buffer
amiraseman 23:a0ce9fa869c2 132 // it is important the format specifier ensures the length will fit in the buffer
amiraseman 23:a0ce9fa869c2 133 }
amiraseman 23:a0ce9fa869c2 134 if (unitFlag==2 || unitFlag==4 ) {//atm
amiraseman 23:a0ce9fa869c2 135 pressure = measurement.pressure*0.0009869; // same idea with floats
amiraseman 23:a0ce9fa869c2 136 int length = sprintf(bufferP,"%.2f",pressure); // print formatted data to buffer
amiraseman 23:a0ce9fa869c2 137 // it is important the format specifier ensures the length will fit in the buffer
amiraseman 23:a0ce9fa869c2 138 }
amiraseman 23:a0ce9fa869c2 139
amiraseman 23:a0ce9fa869c2 140 }
amiraseman 23:a0ce9fa869c2 141
amiraseman 23:a0ce9fa869c2 142
amiraseman 23:a0ce9fa869c2 143
amiraseman 23:a0ce9fa869c2 144
amiraseman 23:a0ce9fa869c2 145 /// Called by the powerSaverTimeout to turn off the lcd and put the mbed in sleep mode
amiraseman 23:a0ce9fa869c2 146 void powerSaverExpired()
amiraseman 23:a0ce9fa869c2 147 {
amiraseman 23:a0ce9fa869c2 148 powerSaverFlag = 1;
amiraseman 23:a0ce9fa869c2 149 }
amiraseman 23:a0ce9fa869c2 150
amiraseman 23:a0ce9fa869c2 151
amiraseman 23:a0ce9fa869c2 152
amiraseman 23:a0ce9fa869c2 153
amiraseman 23:a0ce9fa869c2 154
amiraseman 23:a0ce9fa869c2 155
amiraseman 23:a0ce9fa869c2 156 /// Checks if the power saver option is set by the user, if yes attach a timeout to call save power; if its not set detach the timeout
amiraseman 23:a0ce9fa869c2 157 void powerSaverCheck() // checks if the powersaverFlag is set
amiraseman 23:a0ce9fa869c2 158 {
amiraseman 23:a0ce9fa869c2 159 if (powerSaverFlag == 1) {
amiraseman 23:a0ce9fa869c2 160 while (1) {
amiraseman 23:a0ce9fa869c2 161 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 162 updateTime();
amiraseman 23:a0ce9fa869c2 163 loggerData();
amiraseman 23:a0ce9fa869c2 164
amiraseman 23:a0ce9fa869c2 165 if (button1Flag || button2Flag || button3Flag || button4Flag) { // if any of the buttons are pressed
amiraseman 23:a0ce9fa869c2 166 powerSaverTimeout.attach(&powerSaverExpired, powerSaverTime); // setup a timeiut to call the savePower function
amiraseman 23:a0ce9fa869c2 167 powerSaverFlag = 0;
amiraseman 23:a0ce9fa869c2 168 lcd.init();
amiraseman 23:a0ce9fa869c2 169 button1Flag = 0 ;
amiraseman 23:a0ce9fa869c2 170 button2Flag = 0 ;
amiraseman 23:a0ce9fa869c2 171 button3Flag = 0 ;
amiraseman 23:a0ce9fa869c2 172 button4Flag = 0 ;
amiraseman 23:a0ce9fa869c2 173 break;
amiraseman 23:a0ce9fa869c2 174 }
amiraseman 23:a0ce9fa869c2 175 lcd.turnOff();
amiraseman 23:a0ce9fa869c2 176 Sleep();
amiraseman 23:a0ce9fa869c2 177 }
amiraseman 23:a0ce9fa869c2 178 }
amiraseman 23:a0ce9fa869c2 179 }
amiraseman 23:a0ce9fa869c2 180
amiraseman 23:a0ce9fa869c2 181
amiraseman 23:a0ce9fa869c2 182
amiraseman 23:a0ce9fa869c2 183 /// Displays the live values of temperature and pressure, refreshes every 1 second
amiraseman 23:a0ce9fa869c2 184 void liveData()
amiraseman 23:a0ce9fa869c2 185 {
amiraseman 23:a0ce9fa869c2 186 timerFlag=1;
amiraseman 23:a0ce9fa869c2 187 timer.attach(&timerExpired,1.0);
amiraseman 23:a0ce9fa869c2 188 while (1) {
amiraseman 23:a0ce9fa869c2 189 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 190 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 191 updateTime();
amiraseman 23:a0ce9fa869c2 192 loggerData();
amiraseman 23:a0ce9fa869c2 193 if (timerFlag) {
amiraseman 23:a0ce9fa869c2 194
amiraseman 23:a0ce9fa869c2 195 yellowLED = 1;
amiraseman 23:a0ce9fa869c2 196 timerFlag=0;
amiraseman 23:a0ce9fa869c2 197 readData();
amiraseman 24:51cbed3fbf5c 198 thresholdCheck();
amiraseman 23:a0ce9fa869c2 199 strncpy(buffer1, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 200 strncpy(buffer2, bufferDate, 14);
amiraseman 23:a0ce9fa869c2 201 strncpy(buffer3, bufferT, 14);
amiraseman 23:a0ce9fa869c2 202 strncpy(buffer4, bufferP, 14);
amiraseman 23:a0ce9fa869c2 203 int dispaly = sprintf (buffer5, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 204 int dispaly1 = sprintf (buffer0, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 205 display();
amiraseman 23:a0ce9fa869c2 206 }
amiraseman 23:a0ce9fa869c2 207 yellowLED = 0;
amiraseman 23:a0ce9fa869c2 208 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 209 button3Flag = 0;
amiraseman 23:a0ce9fa869c2 210 timer.detach();
amiraseman 23:a0ce9fa869c2 211 break;
amiraseman 23:a0ce9fa869c2 212 }
amiraseman 23:a0ce9fa869c2 213 }
amiraseman 23:a0ce9fa869c2 214 }
amiraseman 23:a0ce9fa869c2 215
amiraseman 23:a0ce9fa869c2 216
amiraseman 23:a0ce9fa869c2 217
amiraseman 23:a0ce9fa869c2 218 /// gets the temperature and pressure data and stores to suitable arrays, saves the arrays to the local file
amiraseman 23:a0ce9fa869c2 219 void loggerData()
amiraseman 23:a0ce9fa869c2 220 {
amiraseman 23:a0ce9fa869c2 221
amiraseman 23:a0ce9fa869c2 222
amiraseman 23:a0ce9fa869c2 223 if(dataLoggerFlag ==1) {
amiraseman 23:a0ce9fa869c2 224 int k ;
amiraseman 23:a0ce9fa869c2 225 int sumTemperature = 0;
amiraseman 23:a0ce9fa869c2 226 int sumPressure = 0;
amiraseman 23:a0ce9fa869c2 227 greenLED = 1;
amiraseman 23:a0ce9fa869c2 228 readData();
amiraseman 24:51cbed3fbf5c 229 thresholdCheck();
amiraseman 23:a0ce9fa869c2 230 dataLoggerFlag=0;
amiraseman 23:a0ce9fa869c2 231 //write the data to the arrays (arrays used to plot graphs)
amiraseman 23:a0ce9fa869c2 232 //read the data from sensor
amiraseman 23:a0ce9fa869c2 233
amiraseman 23:a0ce9fa869c2 234
amiraseman 23:a0ce9fa869c2 235 //reads the saved data back from the local file
amiraseman 23:a0ce9fa869c2 236
amiraseman 23:a0ce9fa869c2 237 FILE* pFilea = fopen("/local/textfile.csv","r"); // open file access
amiraseman 23:a0ce9fa869c2 238
amiraseman 23:a0ce9fa869c2 239 if (pFilea) {//checks if any data is available from the previous readings
amiraseman 23:a0ce9fa869c2 240 fscanf (pFilea, "%s\n %s\n %s\n %s\n", temperatureRecieved,pressureRecieved,timeRecieved,dateRecieved);
amiraseman 23:a0ce9fa869c2 241 fclose (pFilea);
amiraseman 23:a0ce9fa869c2 242
amiraseman 23:a0ce9fa869c2 243
amiraseman 23:a0ce9fa869c2 244 //initialises the arrays with the saved data from the past
amiraseman 23:a0ce9fa869c2 245 strcpy (temperatureSent,temperatureRecieved);
amiraseman 23:a0ce9fa869c2 246 strcpy (pressureSent,pressureRecieved);
amiraseman 23:a0ce9fa869c2 247 strcpy (timeSent,timeRecieved);
amiraseman 23:a0ce9fa869c2 248 strcpy (dateSent,dateRecieved);
amiraseman 23:a0ce9fa869c2 249 }
amiraseman 23:a0ce9fa869c2 250
amiraseman 23:a0ce9fa869c2 251
amiraseman 23:a0ce9fa869c2 252 //inserts the int values to char arrays to save them to the local file
amiraseman 23:a0ce9fa869c2 253 strcat(temperatureSent,bufferT);
amiraseman 23:a0ce9fa869c2 254 strcat(temperatureSent,",");
amiraseman 23:a0ce9fa869c2 255 strcat(pressureSent,bufferP);
amiraseman 23:a0ce9fa869c2 256 strcat(pressureSent,",");
amiraseman 23:a0ce9fa869c2 257
amiraseman 23:a0ce9fa869c2 258
amiraseman 23:a0ce9fa869c2 259
amiraseman 23:a0ce9fa869c2 260 //apends the new time and current stamp to the array with , between them
amiraseman 23:a0ce9fa869c2 261 strcat(timeSent,bufferTime);
amiraseman 23:a0ce9fa869c2 262 strcat(timeSent,",");
amiraseman 23:a0ce9fa869c2 263 strcat (dateSent,bufferDate);
amiraseman 23:a0ce9fa869c2 264 strcat (dateSent,",");
amiraseman 23:a0ce9fa869c2 265
amiraseman 23:a0ce9fa869c2 266 //send the arrays above to the local file
amiraseman 23:a0ce9fa869c2 267 saveToFile(temperatureSent,pressureSent,timeSent,dateSent);
amiraseman 23:a0ce9fa869c2 268 //serial.printf ("sent temp %s\nsent pressure %s\nsent time %s\nsent date %s\n",temperatureSent,pressureSent,timeSent,dateSent);
amiraseman 23:a0ce9fa869c2 269
amiraseman 23:a0ce9fa869c2 270 //reads the saved data back from the local file
amiraseman 23:a0ce9fa869c2 271
amiraseman 23:a0ce9fa869c2 272 FILE* pFileb = fopen("/local/textfile.csv","r"); // open file access
amiraseman 23:a0ce9fa869c2 273 fscanf (pFileb, "%s\n %s\n %s\n %s\n", temperatureRecieved,pressureRecieved,timeRecieved,dateRecieved);
amiraseman 23:a0ce9fa869c2 274 fclose (pFileb);
amiraseman 23:a0ce9fa869c2 275
amiraseman 23:a0ce9fa869c2 276 //serial.printf ("rec temp %s\nrec pressure %s\nrec time %s\nrec date %s\n",temperatureRecieved,pressureRecieved,timeRecieved,dateRecieved);
amiraseman 23:a0ce9fa869c2 277
amiraseman 23:a0ce9fa869c2 278
amiraseman 23:a0ce9fa869c2 279 //seperates the array into tokens(seperated after the delimiter , )
amiraseman 23:a0ce9fa869c2 280 pch = strtok (timeRecieved,",");//pch is the arguement of the for str
amiraseman 23:a0ce9fa869c2 281 while (pch != NULL) {
amiraseman 23:a0ce9fa869c2 282 //serial.printf (" splitted time = %s\n",pch);
amiraseman 23:a0ce9fa869c2 283 pch = strtok (NULL, ",");
amiraseman 23:a0ce9fa869c2 284 }
amiraseman 23:a0ce9fa869c2 285 pch1 = strtok (dateRecieved,",");
amiraseman 23:a0ce9fa869c2 286 while (pch1 != NULL) {
amiraseman 23:a0ce9fa869c2 287 //serial.printf (" splitted date= %s\n",pch1);
amiraseman 23:a0ce9fa869c2 288 pch1 = strtok (NULL, ",");
amiraseman 23:a0ce9fa869c2 289 }
amiraseman 23:a0ce9fa869c2 290 pch2 = strtok (temperatureRecieved,",");
amiraseman 23:a0ce9fa869c2 291 int p=0;
amiraseman 23:a0ce9fa869c2 292 while (pch2 != NULL) {
amiraseman 23:a0ce9fa869c2 293 //serial.printf (" splitted temperature = %s\n",pch2);
amiraseman 23:a0ce9fa869c2 294 arrayT[p]=atof(pch2);
amiraseman 23:a0ce9fa869c2 295 pch2 = strtok (NULL, ",");
amiraseman 23:a0ce9fa869c2 296 p++;
amiraseman 23:a0ce9fa869c2 297 }
amiraseman 23:a0ce9fa869c2 298
amiraseman 23:a0ce9fa869c2 299 p=0;
amiraseman 23:a0ce9fa869c2 300 pch3 = strtok (pressureRecieved,",");
amiraseman 23:a0ce9fa869c2 301 while (pch3 != NULL) {
amiraseman 23:a0ce9fa869c2 302 // serial.printf (" splitted pressure= %s\n",pch3);
amiraseman 23:a0ce9fa869c2 303 arrayP[p]=atof(pch3);
amiraseman 23:a0ce9fa869c2 304 pch3 = strtok (NULL, ",");
amiraseman 23:a0ce9fa869c2 305 p++;
amiraseman 23:a0ce9fa869c2 306 }
amiraseman 23:a0ce9fa869c2 307
amiraseman 23:a0ce9fa869c2 308 // calculate the average value of the arrays and save them to an integer
amiraseman 23:a0ce9fa869c2 309
amiraseman 23:a0ce9fa869c2 310
amiraseman 23:a0ce9fa869c2 311
amiraseman 25:fa65a9cc78f0 312 minTemperature = arrayT[0]; // sets the min to the first value in the array
amiraseman 25:fa65a9cc78f0 313 minPressure = arrayP[0];
amiraseman 25:fa65a9cc78f0 314 maxTemperature = arrayT[0];
amiraseman 25:fa65a9cc78f0 315 maxPressure = arrayP[0];
amiraseman 23:a0ce9fa869c2 316
amiraseman 23:a0ce9fa869c2 317
amiraseman 23:a0ce9fa869c2 318 for (k = 0 ; k<p ; k++) { // loops through the arrays
amiraseman 23:a0ce9fa869c2 319 // printf("arrayT = %lf\n",arrayT[k]);
amiraseman 23:a0ce9fa869c2 320 // printf("arrayP = %lf\n",arrayP[k]);
amiraseman 23:a0ce9fa869c2 321
amiraseman 23:a0ce9fa869c2 322
amiraseman 23:a0ce9fa869c2 323 if (unitFlag==1 || unitFlag==2 ) { //c
amiraseman 23:a0ce9fa869c2 324 arrayTG[k]=(arrayT[k]/60);
amiraseman 23:a0ce9fa869c2 325 }
amiraseman 23:a0ce9fa869c2 326 if (unitFlag==3 || unitFlag==4 ) {//f
amiraseman 23:a0ce9fa869c2 327 arrayTG[k]=(arrayT[k]/140);
amiraseman 23:a0ce9fa869c2 328 }
amiraseman 23:a0ce9fa869c2 329
amiraseman 23:a0ce9fa869c2 330
amiraseman 23:a0ce9fa869c2 331
amiraseman 23:a0ce9fa869c2 332
amiraseman 23:a0ce9fa869c2 333 if (unitFlag==1 || unitFlag==3 ) {//mb
amiraseman 23:a0ce9fa869c2 334 arrayPG[k]=(arrayP[k]/1500);
amiraseman 23:a0ce9fa869c2 335 }
amiraseman 23:a0ce9fa869c2 336 if (unitFlag==2 || unitFlag==4 ) {//atm
amiraseman 23:a0ce9fa869c2 337 arrayPG[k]=(arrayP[k]/2);
amiraseman 23:a0ce9fa869c2 338 }
amiraseman 25:fa65a9cc78f0 339
amiraseman 25:fa65a9cc78f0 340
amiraseman 23:a0ce9fa869c2 341
amiraseman 23:a0ce9fa869c2 342 sumTemperature += arrayT[k]; // calculates the sum of the stored values
amiraseman 23:a0ce9fa869c2 343 averageTemperature = sumTemperature/(k+1) ; //calculates the average value
amiraseman 23:a0ce9fa869c2 344
amiraseman 23:a0ce9fa869c2 345 sumPressure += arrayP[k]; // calculates the sum of the stored values
amiraseman 23:a0ce9fa869c2 346 averagePressure =(sumPressure/(k+1)) ; //calculates the average value
amiraseman 23:a0ce9fa869c2 347
amiraseman 23:a0ce9fa869c2 348 if(arrayT[k]>maxTemperature) { // checks if any of the values in the array is bigger than the fist value
amiraseman 23:a0ce9fa869c2 349 maxTemperature=arrayT[k]; // if any greater values, sets the max value to that
amiraseman 23:a0ce9fa869c2 350 }
amiraseman 23:a0ce9fa869c2 351 if(arrayT[k]<minTemperature) { // finds the smallest value of the array
amiraseman 23:a0ce9fa869c2 352 minTemperature=arrayT[k];
amiraseman 23:a0ce9fa869c2 353 }
amiraseman 23:a0ce9fa869c2 354 if(arrayP[k]>maxPressure) { // checks if any of the values in the array is bigger than the fist value
amiraseman 23:a0ce9fa869c2 355 maxPressure=(arrayP[k]); // if any greater values, sets the max value to that
amiraseman 23:a0ce9fa869c2 356 }
amiraseman 23:a0ce9fa869c2 357 if(arrayP[k]<maxPressure) {
amiraseman 23:a0ce9fa869c2 358 minPressure=(arrayP[k]);
amiraseman 23:a0ce9fa869c2 359 }
amiraseman 23:a0ce9fa869c2 360
amiraseman 23:a0ce9fa869c2 361 }
amiraseman 23:a0ce9fa869c2 362
amiraseman 23:a0ce9fa869c2 363
amiraseman 23:a0ce9fa869c2 364
amiraseman 23:a0ce9fa869c2 365 if (p>83) { // if the number of reading taken is more than 84 clear the arrays and the local file
amiraseman 23:a0ce9fa869c2 366 strcpy (temperatureSent,"");
amiraseman 23:a0ce9fa869c2 367 strcpy (pressureSent,"");
amiraseman 23:a0ce9fa869c2 368 strcpy (timeSent,"");
amiraseman 23:a0ce9fa869c2 369 strcpy (dateSent,"");
amiraseman 23:a0ce9fa869c2 370 }
amiraseman 23:a0ce9fa869c2 371 }
amiraseman 23:a0ce9fa869c2 372 greenLED = 0;
amiraseman 23:a0ce9fa869c2 373 }
amiraseman 23:a0ce9fa869c2 374
amiraseman 23:a0ce9fa869c2 375
amiraseman 23:a0ce9fa869c2 376
amiraseman 23:a0ce9fa869c2 377
amiraseman 23:a0ce9fa869c2 378 /// Show a summery of minimum maximum and average values for temperature and pressure as well as the temperature-time and pressure_time graphs
amiraseman 23:a0ce9fa869c2 379 void dataLogger()
amiraseman 23:a0ce9fa869c2 380 {
amiraseman 23:a0ce9fa869c2 381 int swipe = 1 ;
amiraseman 23:a0ce9fa869c2 382 while (1) {
amiraseman 23:a0ce9fa869c2 383 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 384 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 385 updateTime();
amiraseman 23:a0ce9fa869c2 386 if (runLoggerFlag) {
amiraseman 23:a0ce9fa869c2 387
amiraseman 23:a0ce9fa869c2 388
amiraseman 23:a0ce9fa869c2 389 loggerData();
amiraseman 23:a0ce9fa869c2 390
amiraseman 23:a0ce9fa869c2 391
amiraseman 23:a0ce9fa869c2 392 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 393 button4Flag = 0 ;
amiraseman 23:a0ce9fa869c2 394 swipe ++;
amiraseman 23:a0ce9fa869c2 395 }
amiraseman 23:a0ce9fa869c2 396 if (swipe > 4) {
amiraseman 23:a0ce9fa869c2 397 swipe = 1;
amiraseman 23:a0ce9fa869c2 398 }
amiraseman 23:a0ce9fa869c2 399
amiraseman 23:a0ce9fa869c2 400 strncpy(buffer0, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 401 int display5 = sprintf (buffer5, " Back Next");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 402
amiraseman 23:a0ce9fa869c2 403 switch (swipe) {
amiraseman 23:a0ce9fa869c2 404 case 1: {
amiraseman 23:a0ce9fa869c2 405 int display1 = sprintf (buffer1, "Temperature");
amiraseman 23:a0ce9fa869c2 406 int display2 = sprintf (buffer2, "Min = %0.2f", minTemperature);
amiraseman 23:a0ce9fa869c2 407 int display3 = sprintf (buffer3, "Max = %0.2f", maxTemperature);
amiraseman 23:a0ce9fa869c2 408 int display4 = sprintf (buffer4, "Avg = %0.2f", averageTemperature);
amiraseman 23:a0ce9fa869c2 409 display();
amiraseman 23:a0ce9fa869c2 410 break;
amiraseman 23:a0ce9fa869c2 411 }
amiraseman 23:a0ce9fa869c2 412 case 2 : {
amiraseman 23:a0ce9fa869c2 413 lcd.clear();
amiraseman 23:a0ce9fa869c2 414 lcd.printString(" Temperature",0,0);
amiraseman 23:a0ce9fa869c2 415 lcd.plotArray(arrayTG);
amiraseman 23:a0ce9fa869c2 416 break;
amiraseman 23:a0ce9fa869c2 417 }
amiraseman 23:a0ce9fa869c2 418 case 3 : {
amiraseman 23:a0ce9fa869c2 419 int display11 = sprintf (buffer1, "Pressure");
amiraseman 23:a0ce9fa869c2 420 int display22 = sprintf (buffer2, "Min = %0.2f", minPressure);
amiraseman 23:a0ce9fa869c2 421 int display33 = sprintf (buffer3, "Max = %0.2f", maxPressure);
amiraseman 23:a0ce9fa869c2 422 int display44 = sprintf (buffer4, "Avg = %0.2f", averagePressure);
amiraseman 23:a0ce9fa869c2 423 display();
amiraseman 23:a0ce9fa869c2 424 break;
amiraseman 23:a0ce9fa869c2 425 }
amiraseman 23:a0ce9fa869c2 426 case 4 : {
amiraseman 23:a0ce9fa869c2 427 lcd.clear();
amiraseman 23:a0ce9fa869c2 428 lcd.printString(" Pressure",0,0);
amiraseman 23:a0ce9fa869c2 429 lcd.plotArray(arrayPG);
amiraseman 23:a0ce9fa869c2 430 break;
amiraseman 23:a0ce9fa869c2 431 }
amiraseman 23:a0ce9fa869c2 432 default :
amiraseman 23:a0ce9fa869c2 433 break;
amiraseman 23:a0ce9fa869c2 434 }
amiraseman 23:a0ce9fa869c2 435 } else {
amiraseman 23:a0ce9fa869c2 436 lcd.clear();
amiraseman 23:a0ce9fa869c2 437 lcd.printString(" To Turn On",0,1);
amiraseman 23:a0ce9fa869c2 438 lcd.printString(" Go To",0,2);
amiraseman 23:a0ce9fa869c2 439 lcd.printString(" Settings",0,3);
amiraseman 23:a0ce9fa869c2 440 lcd.printString ("Back",0,5);
amiraseman 23:a0ce9fa869c2 441
amiraseman 23:a0ce9fa869c2 442 }
amiraseman 23:a0ce9fa869c2 443
amiraseman 23:a0ce9fa869c2 444 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 445 button3Flag=0;
amiraseman 23:a0ce9fa869c2 446 break;
amiraseman 23:a0ce9fa869c2 447 }
amiraseman 25:fa65a9cc78f0 448 wait(0.1);
amiraseman 23:a0ce9fa869c2 449 }
amiraseman 23:a0ce9fa869c2 450 }
amiraseman 23:a0ce9fa869c2 451
amiraseman 23:a0ce9fa869c2 452
amiraseman 23:a0ce9fa869c2 453
amiraseman 23:a0ce9fa869c2 454 /// Checks if the current temperture and pressure is equal to one of the thresholds set by the user, if yes it triggers the alarm and sets the buzzer
amiraseman 23:a0ce9fa869c2 455 void thresholdCheck()
amiraseman 23:a0ce9fa869c2 456 {
amiraseman 23:a0ce9fa869c2 457 if (thresholdAlarmFlag) {
amiraseman 23:a0ce9fa869c2 458 thresholdAlarmFlag = 1;
amiraseman 25:fa65a9cc78f0 459 if (int(temperature) <= fsmH[0].output) { //if the current temp is less than the set threshold
amiraseman 23:a0ce9fa869c2 460 while (1) {
amiraseman 23:a0ce9fa869c2 461 redLED = 0 ;
amiraseman 23:a0ce9fa869c2 462 strncpy(buffer0, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 463 int display2 = sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 464 int display0 = sprintf (buffer2, "Threshold");
amiraseman 23:a0ce9fa869c2 465 int display1 = sprintf (buffer3, "Reached!");
amiraseman 23:a0ce9fa869c2 466 int display4 = sprintf (buffer4, "%0.1f!",temperature);
amiraseman 23:a0ce9fa869c2 467 int display5 = sprintf (buffer5, "Stop");
amiraseman 23:a0ce9fa869c2 468 display();
amiraseman 23:a0ce9fa869c2 469 for (int i=0; i<=11; i++) {
amiraseman 23:a0ce9fa869c2 470 buzzer.period(1/(frequency[i])); // set PWM period
amiraseman 23:a0ce9fa869c2 471 buzzer=0.5; // set duty cycle
amiraseman 23:a0ce9fa869c2 472 //wait(0.5); // hold for beat period
amiraseman 23:a0ce9fa869c2 473 redLED = 1 ;
amiraseman 23:a0ce9fa869c2 474 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 475 buzzer = 0 ;
amiraseman 23:a0ce9fa869c2 476 lcd.setBrightness(0.5);
amiraseman 23:a0ce9fa869c2 477 button3Flag=0;
amiraseman 23:a0ce9fa869c2 478 goto exit ;
amiraseman 23:a0ce9fa869c2 479 }
amiraseman 23:a0ce9fa869c2 480 }
amiraseman 23:a0ce9fa869c2 481 }
amiraseman 23:a0ce9fa869c2 482 }
amiraseman 25:fa65a9cc78f0 483 if (int(temperature) >= fsmH[1].output) { //if the current temp is greater than the set threshold
amiraseman 23:a0ce9fa869c2 484 while (1) {
amiraseman 23:a0ce9fa869c2 485 redLED = 0 ;
amiraseman 23:a0ce9fa869c2 486 strncpy(buffer0, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 487 int display2 = sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 488 int display0 = sprintf (buffer2, "Threshold");
amiraseman 23:a0ce9fa869c2 489 int display1 = sprintf (buffer3, "Reached!");
amiraseman 23:a0ce9fa869c2 490 int display4 = sprintf (buffer4, "%0.1f!",temperature );
amiraseman 23:a0ce9fa869c2 491 int display5 = sprintf (buffer5, "Stop");
amiraseman 23:a0ce9fa869c2 492 display();
amiraseman 23:a0ce9fa869c2 493 for (int i=0; i<=11; i++) {
amiraseman 23:a0ce9fa869c2 494 buzzer.period(1/(frequency[i])); // set PWM period
amiraseman 23:a0ce9fa869c2 495 buzzer=0.5; // set duty cycle
amiraseman 23:a0ce9fa869c2 496 //wait(0.5); // hold for beat period
amiraseman 23:a0ce9fa869c2 497 redLED = 1 ;
amiraseman 23:a0ce9fa869c2 498 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 499 buzzer = 0 ;
amiraseman 23:a0ce9fa869c2 500 lcd.setBrightness(0.5);
amiraseman 23:a0ce9fa869c2 501 button3Flag=0;
amiraseman 23:a0ce9fa869c2 502 goto exit ;
amiraseman 23:a0ce9fa869c2 503 }
amiraseman 23:a0ce9fa869c2 504 }
amiraseman 23:a0ce9fa869c2 505 }
amiraseman 23:a0ce9fa869c2 506 }
amiraseman 25:fa65a9cc78f0 507 if (int(pressure) <= fsmH[2].output) { //if the current pressure is less than the set threshold
amiraseman 23:a0ce9fa869c2 508 while (1) {
amiraseman 23:a0ce9fa869c2 509 redLED = 0 ;
amiraseman 23:a0ce9fa869c2 510 strncpy(buffer0, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 511 int display2 = sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 512 int display0 = sprintf (buffer2, "Threshold");
amiraseman 23:a0ce9fa869c2 513 int display1 = sprintf (buffer3, "Reached!");
amiraseman 23:a0ce9fa869c2 514 int display4 = sprintf (buffer4, "%0.1f!",pressure);
amiraseman 23:a0ce9fa869c2 515 int display5 = sprintf (buffer5, "Stop");
amiraseman 23:a0ce9fa869c2 516 display();
amiraseman 23:a0ce9fa869c2 517 for (int i=0; i<=11; i++) {
amiraseman 23:a0ce9fa869c2 518 buzzer.period(1/(frequency[i])); // set PWM period
amiraseman 23:a0ce9fa869c2 519 buzzer=0.5; // set duty cycle
amiraseman 23:a0ce9fa869c2 520 redLED = 1 ;
amiraseman 23:a0ce9fa869c2 521 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 522 buzzer = 0 ;
amiraseman 23:a0ce9fa869c2 523 button3Flag=0;
amiraseman 23:a0ce9fa869c2 524 goto exit ;
amiraseman 23:a0ce9fa869c2 525 }
amiraseman 23:a0ce9fa869c2 526 }
amiraseman 23:a0ce9fa869c2 527 }
amiraseman 23:a0ce9fa869c2 528 }
amiraseman 25:fa65a9cc78f0 529 if (int(pressure) >= fsmH[3].output) { //if the current pressure is greater than the set threshold
amiraseman 23:a0ce9fa869c2 530
amiraseman 23:a0ce9fa869c2 531 while (1) {
amiraseman 23:a0ce9fa869c2 532 redLED = 0 ;
amiraseman 23:a0ce9fa869c2 533 strncpy(buffer0, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 534 int display2 = sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 535 int display0 = sprintf (buffer2, "Threshold");
amiraseman 23:a0ce9fa869c2 536 int display1 = sprintf (buffer3, "Reached!");
amiraseman 23:a0ce9fa869c2 537 int display4 = sprintf (buffer4, "%0.1f!",pressure);
amiraseman 23:a0ce9fa869c2 538 int display5 = sprintf (buffer5, "Stop");
amiraseman 23:a0ce9fa869c2 539 display();
amiraseman 23:a0ce9fa869c2 540 for (int i=0; i<=11; i++) {
amiraseman 23:a0ce9fa869c2 541 buzzer.period(1/(frequency[i])); // set PWM period
amiraseman 23:a0ce9fa869c2 542 buzzer=1; // set duty cycle
amiraseman 23:a0ce9fa869c2 543 redLED = 1 ;
amiraseman 23:a0ce9fa869c2 544 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 545 buzzer = 0 ;
amiraseman 23:a0ce9fa869c2 546 button3Flag=0;
amiraseman 23:a0ce9fa869c2 547 goto exit ;
amiraseman 23:a0ce9fa869c2 548 }
amiraseman 23:a0ce9fa869c2 549 }
amiraseman 23:a0ce9fa869c2 550 }
amiraseman 23:a0ce9fa869c2 551 }
amiraseman 23:a0ce9fa869c2 552 exit:
amiraseman 23:a0ce9fa869c2 553 redLED = 0 ;
amiraseman 23:a0ce9fa869c2 554 }
amiraseman 23:a0ce9fa869c2 555
amiraseman 23:a0ce9fa869c2 556 }
amiraseman 23:a0ce9fa869c2 557
amiraseman 23:a0ce9fa869c2 558 ///Allows the user to set the minimum and maximum values of temperature and pressure for the thresholds
amiraseman 23:a0ce9fa869c2 559 void threshold()
amiraseman 23:a0ce9fa869c2 560 {
amiraseman 23:a0ce9fa869c2 561 state = 0;
amiraseman 23:a0ce9fa869c2 562 //sets the initial threshhold values to the values recieved from the sensor
amiraseman 23:a0ce9fa869c2 563 readData();
amiraseman 25:fa65a9cc78f0 564 fsmH[0].output = temperature-20;
amiraseman 23:a0ce9fa869c2 565 fsmH[1].output = temperature;
amiraseman 25:fa65a9cc78f0 566 fsmH[2].output = pressure-100;
amiraseman 23:a0ce9fa869c2 567 fsmH[3].output = pressure;
amiraseman 23:a0ce9fa869c2 568
amiraseman 23:a0ce9fa869c2 569 while (1) {
amiraseman 23:a0ce9fa869c2 570 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 571 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 572 updateTime();
amiraseman 23:a0ce9fa869c2 573 loggerData();
amiraseman 23:a0ce9fa869c2 574
amiraseman 23:a0ce9fa869c2 575
amiraseman 23:a0ce9fa869c2 576
amiraseman 23:a0ce9fa869c2 577 int display0 = sprintf (buffer0, " Back Save");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 578 int display1 = sprintf (buffer1, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 579 int display2 = sprintf (buffer2, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 580 int display3 = sprintf (buffer3, ">>%s %d", fsmH[state].title,fsmH[state].output);//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 581 int display4 = sprintf (buffer4, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 582 int display5 = sprintf (buffer5, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 583
amiraseman 23:a0ce9fa869c2 584
amiraseman 23:a0ce9fa869c2 585 display();
amiraseman 23:a0ce9fa869c2 586
amiraseman 23:a0ce9fa869c2 587
amiraseman 23:a0ce9fa869c2 588
amiraseman 23:a0ce9fa869c2 589 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 590 button4Flag= 0;
amiraseman 23:a0ce9fa869c2 591 fsmH[state].output ++;
amiraseman 23:a0ce9fa869c2 592 }
amiraseman 23:a0ce9fa869c2 593
amiraseman 23:a0ce9fa869c2 594
amiraseman 23:a0ce9fa869c2 595
amiraseman 23:a0ce9fa869c2 596
amiraseman 23:a0ce9fa869c2 597 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 598 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 599 button1Flag=0;
amiraseman 23:a0ce9fa869c2 600 state=fsmH[state].nextState[1];
amiraseman 23:a0ce9fa869c2 601 }
amiraseman 23:a0ce9fa869c2 602 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 603 button2Flag=0;
amiraseman 23:a0ce9fa869c2 604 state=fsmH[state].nextState[0];
amiraseman 23:a0ce9fa869c2 605 }
amiraseman 23:a0ce9fa869c2 606
amiraseman 23:a0ce9fa869c2 607
amiraseman 23:a0ce9fa869c2 608 //checks the limits of the values
amiraseman 25:fa65a9cc78f0 609 if (fsmH[0].output >(temperature*1.5)) { //min temperature
amiraseman 25:fa65a9cc78f0 610 fsmH[0].output = -(temperature*1.5) ;
amiraseman 23:a0ce9fa869c2 611 }
amiraseman 25:fa65a9cc78f0 612 if (fsmH[1].output>(temperature*1.5)) { // max temperature
amiraseman 25:fa65a9cc78f0 613 fsmH[1].output = -(temperature*1.5) ;
amiraseman 23:a0ce9fa869c2 614 }
amiraseman 25:fa65a9cc78f0 615 if (fsmH[2].output>(pressure*1.10)) { //min pressure
amiraseman 25:fa65a9cc78f0 616 fsmH[2].output = -(pressure*1.10) ;
amiraseman 23:a0ce9fa869c2 617 }
amiraseman 25:fa65a9cc78f0 618 if (fsmH[3].output>(pressure*1.10)) { //max pressure
amiraseman 25:fa65a9cc78f0 619 fsmH[3].output = -(pressure*1.10) ;
amiraseman 23:a0ce9fa869c2 620 }
amiraseman 23:a0ce9fa869c2 621
amiraseman 23:a0ce9fa869c2 622
amiraseman 23:a0ce9fa869c2 623 if (button3Flag) {//if wants to go back
amiraseman 23:a0ce9fa869c2 624 button3Flag=0;
amiraseman 23:a0ce9fa869c2 625 state = 0;
amiraseman 23:a0ce9fa869c2 626 while (1) { //runs a while loop
amiraseman 23:a0ce9fa869c2 627 int display0 = sprintf (buffer0, "");
amiraseman 23:a0ce9fa869c2 628 int display1 = sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 629 int display2 = sprintf (buffer2, "Set Thresholds?"); //asks to set the threshold
amiraseman 23:a0ce9fa869c2 630 int display3 = sprintf (buffer3, ">>%s", fsmG[state].title); // yes or no (1 or 0 output)
amiraseman 23:a0ce9fa869c2 631 int display4 = sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 632 int display5 = sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 633 display();
amiraseman 23:a0ce9fa869c2 634 thresholdAlarmFlag = fsmG[state].output ; //yes or no (1 or 0)
amiraseman 23:a0ce9fa869c2 635
amiraseman 23:a0ce9fa869c2 636
amiraseman 23:a0ce9fa869c2 637 //Navigates to the next state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 638 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 639 button1Flag=0;
amiraseman 23:a0ce9fa869c2 640 state=fsmG[state].nextState[1];
amiraseman 23:a0ce9fa869c2 641 }
amiraseman 23:a0ce9fa869c2 642 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 643 button2Flag=0;
amiraseman 23:a0ce9fa869c2 644 state=fsmG[state].nextState[0];
amiraseman 23:a0ce9fa869c2 645 }
amiraseman 23:a0ce9fa869c2 646
amiraseman 23:a0ce9fa869c2 647
amiraseman 23:a0ce9fa869c2 648
amiraseman 23:a0ce9fa869c2 649 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 650 //serial.printf("thresholds flag :%i \n",fsmG[state].output);
amiraseman 23:a0ce9fa869c2 651 //serial.printf("thresholds: mint%i maxt%i minP%i maxP %i \n",fsmH[0].output,fsmH[1].output,fsmH[2].output,fsmH[3].output);
amiraseman 25:fa65a9cc78f0 652 break;
amiraseman 23:a0ce9fa869c2 653 }
amiraseman 23:a0ce9fa869c2 654 }
amiraseman 23:a0ce9fa869c2 655 }
amiraseman 25:fa65a9cc78f0 656 if (button3Flag) {
amiraseman 25:fa65a9cc78f0 657 button3Flag=0;
amiraseman 25:fa65a9cc78f0 658 break ;
amiraseman 25:fa65a9cc78f0 659 }
amiraseman 23:a0ce9fa869c2 660 }
amiraseman 23:a0ce9fa869c2 661 }
amiraseman 23:a0ce9fa869c2 662
amiraseman 23:a0ce9fa869c2 663
amiraseman 23:a0ce9fa869c2 664
amiraseman 23:a0ce9fa869c2 665
amiraseman 23:a0ce9fa869c2 666
amiraseman 23:a0ce9fa869c2 667 /// Compares the time set by the user in the alarm clock section with the current time, turn on the buzzer if they are equal
amiraseman 23:a0ce9fa869c2 668 void alarmClockCheck()
amiraseman 23:a0ce9fa869c2 669 {
amiraseman 23:a0ce9fa869c2 670 if (alarmClockFlag) {
amiraseman 23:a0ce9fa869c2 671 if (currentTime == UNIXdate) { //if the current time is equal to the time set by user
amiraseman 23:a0ce9fa869c2 672 //serial.printf("Alarm clock flag is set\n");
amiraseman 23:a0ce9fa869c2 673 alarmClockFlag =0 ;
amiraseman 23:a0ce9fa869c2 674 while (1) {
amiraseman 23:a0ce9fa869c2 675 int display0 = sprintf (buffer0, "");
amiraseman 23:a0ce9fa869c2 676 int display1 = sprintf (buffer1, "Alarm !");
amiraseman 23:a0ce9fa869c2 677 strncpy(buffer2, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 678 int display2 = sprintf (buffer3, "");
amiraseman 23:a0ce9fa869c2 679 int display4 = sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 680 int display5 = sprintf (buffer5, "Stop");
amiraseman 23:a0ce9fa869c2 681 display();
amiraseman 23:a0ce9fa869c2 682 for (int i=0; i<=11; i++) {
amiraseman 23:a0ce9fa869c2 683 buzzer.period(1/(frequency[i])); // set PWM period
amiraseman 23:a0ce9fa869c2 684 buzzer=0.5; // set duty cycle
amiraseman 23:a0ce9fa869c2 685 wait(0.5); // hold for beat period
amiraseman 23:a0ce9fa869c2 686 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 687 buzzer = 0 ;
amiraseman 23:a0ce9fa869c2 688 lcd.setBrightness(0.5);
amiraseman 23:a0ce9fa869c2 689 break;
amiraseman 23:a0ce9fa869c2 690 }
amiraseman 23:a0ce9fa869c2 691 }
amiraseman 23:a0ce9fa869c2 692 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 693 button3Flag=0;
amiraseman 23:a0ce9fa869c2 694 break;
amiraseman 23:a0ce9fa869c2 695 }
amiraseman 23:a0ce9fa869c2 696
amiraseman 23:a0ce9fa869c2 697 }
amiraseman 23:a0ce9fa869c2 698 }
amiraseman 23:a0ce9fa869c2 699 }
amiraseman 23:a0ce9fa869c2 700 }
amiraseman 23:a0ce9fa869c2 701
amiraseman 23:a0ce9fa869c2 702
amiraseman 23:a0ce9fa869c2 703
amiraseman 23:a0ce9fa869c2 704
amiraseman 23:a0ce9fa869c2 705
amiraseman 23:a0ce9fa869c2 706
amiraseman 23:a0ce9fa869c2 707 /// Allows the user to set the time for the alarm clock
amiraseman 23:a0ce9fa869c2 708 void alarmClock ()
amiraseman 23:a0ce9fa869c2 709 {
amiraseman 23:a0ce9fa869c2 710 state = 0;
amiraseman 23:a0ce9fa869c2 711 while (1) {
amiraseman 23:a0ce9fa869c2 712 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 713 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 714 updateTime();
amiraseman 23:a0ce9fa869c2 715 loggerData();
amiraseman 23:a0ce9fa869c2 716
amiraseman 23:a0ce9fa869c2 717
amiraseman 23:a0ce9fa869c2 718 int display0 = sprintf (buffer0, " Back Save");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 719 int display1 = sprintf (buffer1, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 720 int display2 = sprintf (buffer2, "" );//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 721 int display3 = sprintf (buffer3, ">>%s %d", fsmC[state].title,fsmC[state].output);//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 722 int display4 = sprintf (buffer4, "" );//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 723 int display5 = sprintf (buffer5, "" );//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 724
amiraseman 23:a0ce9fa869c2 725
amiraseman 23:a0ce9fa869c2 726
amiraseman 23:a0ce9fa869c2 727 display();
amiraseman 23:a0ce9fa869c2 728
amiraseman 23:a0ce9fa869c2 729
amiraseman 23:a0ce9fa869c2 730
amiraseman 23:a0ce9fa869c2 731 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 732 button4Flag= 0;
amiraseman 23:a0ce9fa869c2 733 fsmC[state].output ++;
amiraseman 23:a0ce9fa869c2 734 calculateUNIXTime();
amiraseman 23:a0ce9fa869c2 735 }
amiraseman 23:a0ce9fa869c2 736
amiraseman 23:a0ce9fa869c2 737
amiraseman 23:a0ce9fa869c2 738
amiraseman 23:a0ce9fa869c2 739 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 740 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 741 button1Flag=0;
amiraseman 23:a0ce9fa869c2 742 state=fsmC[state].nextState[1];
amiraseman 23:a0ce9fa869c2 743 }
amiraseman 23:a0ce9fa869c2 744 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 745 button2Flag=0;
amiraseman 23:a0ce9fa869c2 746 state=fsmC[state].nextState[0];
amiraseman 23:a0ce9fa869c2 747 }
amiraseman 23:a0ce9fa869c2 748
amiraseman 23:a0ce9fa869c2 749
amiraseman 23:a0ce9fa869c2 750
amiraseman 23:a0ce9fa869c2 751 //checks the limits of the values
amiraseman 23:a0ce9fa869c2 752 if (fsmC[0].output >23) { //hour
amiraseman 23:a0ce9fa869c2 753 fsmC[0].output = 0 ;
amiraseman 23:a0ce9fa869c2 754 }
amiraseman 23:a0ce9fa869c2 755 if (fsmC[1].output>59) { // minute
amiraseman 23:a0ce9fa869c2 756 fsmC[1].output = 0 ;
amiraseman 23:a0ce9fa869c2 757 }
amiraseman 23:a0ce9fa869c2 758 if (fsmC[3].output>11) { //month
amiraseman 23:a0ce9fa869c2 759 fsmC[3].output = 0 ;
amiraseman 23:a0ce9fa869c2 760 }
amiraseman 23:a0ce9fa869c2 761 if (fsmC[2].output>31) { //day
amiraseman 23:a0ce9fa869c2 762 fsmC[2].output = 1 ;
amiraseman 23:a0ce9fa869c2 763 }
amiraseman 23:a0ce9fa869c2 764 if (fsmC[4].output>2030) { //year
amiraseman 23:a0ce9fa869c2 765 fsmC[4].output = 2015 ;
amiraseman 23:a0ce9fa869c2 766 }
amiraseman 23:a0ce9fa869c2 767
amiraseman 23:a0ce9fa869c2 768
amiraseman 23:a0ce9fa869c2 769
amiraseman 23:a0ce9fa869c2 770 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 771 button3Flag=0;
amiraseman 23:a0ce9fa869c2 772 while (1) {
amiraseman 23:a0ce9fa869c2 773 int display0 = sprintf (buffer0, "");
amiraseman 23:a0ce9fa869c2 774 int display1 = sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 775 int display2 = sprintf (buffer2, "Set Alarm?");
amiraseman 23:a0ce9fa869c2 776 int display3 = sprintf (buffer3, ">>%s", fsmG[state].title);
amiraseman 23:a0ce9fa869c2 777 int display4 = sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 778 int display5 = sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 779 display();
amiraseman 23:a0ce9fa869c2 780 alarmClockFlag = fsmG[state].output ;
amiraseman 23:a0ce9fa869c2 781 if (state>1) {
amiraseman 23:a0ce9fa869c2 782 state = 0;
amiraseman 23:a0ce9fa869c2 783 }
amiraseman 23:a0ce9fa869c2 784 if (state<0) {
amiraseman 23:a0ce9fa869c2 785 state = 1;
amiraseman 23:a0ce9fa869c2 786 }
amiraseman 23:a0ce9fa869c2 787 if (button3Flag) {
amiraseman 25:fa65a9cc78f0 788 break ;
amiraseman 23:a0ce9fa869c2 789 }
amiraseman 23:a0ce9fa869c2 790
amiraseman 23:a0ce9fa869c2 791
amiraseman 23:a0ce9fa869c2 792 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 793 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 794 button1Flag=0;
amiraseman 23:a0ce9fa869c2 795 state=fsmG[state].nextState[1];
amiraseman 23:a0ce9fa869c2 796 }
amiraseman 23:a0ce9fa869c2 797 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 798 button2Flag=0;
amiraseman 23:a0ce9fa869c2 799 state=fsmG[state].nextState[0];
amiraseman 23:a0ce9fa869c2 800 }
amiraseman 23:a0ce9fa869c2 801 }
amiraseman 23:a0ce9fa869c2 802 }
amiraseman 25:fa65a9cc78f0 803 if (button3Flag) {
amiraseman 25:fa65a9cc78f0 804 button3Flag=0;
amiraseman 25:fa65a9cc78f0 805 break ;
amiraseman 25:fa65a9cc78f0 806 }
amiraseman 23:a0ce9fa869c2 807 }
amiraseman 23:a0ce9fa869c2 808 }
amiraseman 23:a0ce9fa869c2 809
amiraseman 23:a0ce9fa869c2 810
amiraseman 23:a0ce9fa869c2 811
amiraseman 23:a0ce9fa869c2 812
amiraseman 23:a0ce9fa869c2 813 ///A menu to indicate the alarm options (Alarm clock and thresholds alarm), also allows the user to navigate through the given options
amiraseman 23:a0ce9fa869c2 814 void alarmsMenu ()
amiraseman 23:a0ce9fa869c2 815 {
amiraseman 23:a0ce9fa869c2 816 state = 0 ;
amiraseman 23:a0ce9fa869c2 817 while (1) {
amiraseman 23:a0ce9fa869c2 818 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 819 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 820 updateTime();
amiraseman 23:a0ce9fa869c2 821 loggerData();
amiraseman 23:a0ce9fa869c2 822 int display0 = sprintf (buffer0, " Back Next");
amiraseman 23:a0ce9fa869c2 823 int display1 = sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 824 int display2 = sprintf (buffer2, "");
amiraseman 23:a0ce9fa869c2 825 int display3 = sprintf (buffer3, ">>%s", fsmF[state].title);
amiraseman 23:a0ce9fa869c2 826 int display4 = sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 827 int display5 = sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 828
amiraseman 23:a0ce9fa869c2 829 display();
amiraseman 23:a0ce9fa869c2 830
amiraseman 23:a0ce9fa869c2 831
amiraseman 23:a0ce9fa869c2 832
amiraseman 23:a0ce9fa869c2 833 if (state > 1) {
amiraseman 23:a0ce9fa869c2 834 state = 0 ;
amiraseman 23:a0ce9fa869c2 835 }
amiraseman 23:a0ce9fa869c2 836 if (state < 0) {
amiraseman 23:a0ce9fa869c2 837 state = 1 ;
amiraseman 23:a0ce9fa869c2 838 }
amiraseman 23:a0ce9fa869c2 839 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 840 button3Flag=0;
amiraseman 23:a0ce9fa869c2 841 state = 0;
amiraseman 23:a0ce9fa869c2 842 break;
amiraseman 23:a0ce9fa869c2 843 }
amiraseman 25:fa65a9cc78f0 844
amiraseman 25:fa65a9cc78f0 845 switch (state) {
amiraseman 25:fa65a9cc78f0 846 case 0: //thresholds
amiraseman 25:fa65a9cc78f0 847
amiraseman 25:fa65a9cc78f0 848 if (button4Flag) {
amiraseman 25:fa65a9cc78f0 849 button4Flag=0;
amiraseman 25:fa65a9cc78f0 850 threshold();
amiraseman 25:fa65a9cc78f0 851 }
amiraseman 25:fa65a9cc78f0 852 break ;
amiraseman 23:a0ce9fa869c2 853
amiraseman 25:fa65a9cc78f0 854 case 1 :
amiraseman 25:fa65a9cc78f0 855 if (button4Flag) {
amiraseman 25:fa65a9cc78f0 856 button4Flag=0;
amiraseman 25:fa65a9cc78f0 857 alarmClock();
amiraseman 25:fa65a9cc78f0 858 }
amiraseman 25:fa65a9cc78f0 859 break ;
amiraseman 25:fa65a9cc78f0 860 default:
amiraseman 25:fa65a9cc78f0 861 break;
amiraseman 23:a0ce9fa869c2 862 }
amiraseman 25:fa65a9cc78f0 863
amiraseman 25:fa65a9cc78f0 864 //Navigates to the next state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 865 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 866 button1Flag=0;
amiraseman 23:a0ce9fa869c2 867 state=fsmF[state].nextState[1];
amiraseman 23:a0ce9fa869c2 868 }
amiraseman 23:a0ce9fa869c2 869 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 870 button2Flag=0;
amiraseman 23:a0ce9fa869c2 871 state=fsmF[state].nextState[0];
amiraseman 23:a0ce9fa869c2 872 }
amiraseman 23:a0ce9fa869c2 873 }
amiraseman 23:a0ce9fa869c2 874 }
amiraseman 23:a0ce9fa869c2 875
amiraseman 23:a0ce9fa869c2 876
amiraseman 23:a0ce9fa869c2 877
amiraseman 23:a0ce9fa869c2 878 /// Allows the user to turn on the data logger and set the time interval between the readings
amiraseman 23:a0ce9fa869c2 879 void dataLoggerSetting()
amiraseman 23:a0ce9fa869c2 880 {
amiraseman 23:a0ce9fa869c2 881 state = runLoggerFlag ; //inits the state to the saved flag by the user in the past
amiraseman 23:a0ce9fa869c2 882 while (1) {
amiraseman 23:a0ce9fa869c2 883 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 884 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 885 updateTime();
amiraseman 23:a0ce9fa869c2 886 loggerData();
amiraseman 23:a0ce9fa869c2 887 sprintf (buffer0, " Back Save");
amiraseman 23:a0ce9fa869c2 888 sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 889 sprintf (buffer2, "Data Logger");
amiraseman 23:a0ce9fa869c2 890 sprintf (buffer3, ">>%s", fsmE[state].title);
amiraseman 23:a0ce9fa869c2 891 if (state == 1) {
amiraseman 23:a0ce9fa869c2 892 sprintf (buffer4, "%i mins", fsmE[state].output/60);
amiraseman 23:a0ce9fa869c2 893 } else { // if the power saver is off it doesnt show the time
amiraseman 23:a0ce9fa869c2 894 sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 895 }
amiraseman 23:a0ce9fa869c2 896 sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 897
amiraseman 23:a0ce9fa869c2 898
amiraseman 23:a0ce9fa869c2 899 display();
amiraseman 23:a0ce9fa869c2 900
amiraseman 23:a0ce9fa869c2 901
amiraseman 23:a0ce9fa869c2 902
amiraseman 23:a0ce9fa869c2 903 runLoggerFlag = state ; //sets the flag to the value of state (0 is off, 1 is on)
amiraseman 23:a0ce9fa869c2 904 dataLoggerTime = fsmE[state].output; //sets the timer to to value of output from the fsm
amiraseman 23:a0ce9fa869c2 905 // serial.printf("data logger Time = %i \n dataLoggerFlag = %i \n",dataLoggerTime , runLoggerFlag);
amiraseman 23:a0ce9fa869c2 906
amiraseman 23:a0ce9fa869c2 907 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 908 button4Flag=0;
amiraseman 23:a0ce9fa869c2 909 fsmE[state].output += 60 ; //adds a minute to the timer when button 4 is pressed
amiraseman 23:a0ce9fa869c2 910 }
amiraseman 23:a0ce9fa869c2 911 if (fsmE[state].output > 1800) {
amiraseman 23:a0ce9fa869c2 912 fsmE[state].output = 60 ;
amiraseman 23:a0ce9fa869c2 913 }
amiraseman 23:a0ce9fa869c2 914
amiraseman 23:a0ce9fa869c2 915 if (state > 1) {
amiraseman 23:a0ce9fa869c2 916 state = 0 ;
amiraseman 23:a0ce9fa869c2 917 }
amiraseman 23:a0ce9fa869c2 918
amiraseman 23:a0ce9fa869c2 919 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 920 if (state == 1) { // if the data logger is swiched on
amiraseman 23:a0ce9fa869c2 921 dataLoggerTimer.attach(&dataLoggerTimerExpired, dataLoggerTime); // set the timer
amiraseman 23:a0ce9fa869c2 922 }
amiraseman 23:a0ce9fa869c2 923 if (state == 0) { // if the data logger is swiched off
amiraseman 23:a0ce9fa869c2 924 dataLoggerTimer.detach(); // detach the timer
amiraseman 23:a0ce9fa869c2 925 }
amiraseman 23:a0ce9fa869c2 926 dataLoggerFlag = 1;
amiraseman 23:a0ce9fa869c2 927 button3Flag=0;
amiraseman 23:a0ce9fa869c2 928 state = 0;
amiraseman 23:a0ce9fa869c2 929 break;
amiraseman 23:a0ce9fa869c2 930 }
amiraseman 23:a0ce9fa869c2 931 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 932 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 933 button1Flag=0;
amiraseman 23:a0ce9fa869c2 934 state=fsmE[state].nextState[1];
amiraseman 23:a0ce9fa869c2 935 }
amiraseman 23:a0ce9fa869c2 936 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 937 button2Flag=0;
amiraseman 23:a0ce9fa869c2 938 state=fsmE[state].nextState[0];
amiraseman 23:a0ce9fa869c2 939 }
amiraseman 23:a0ce9fa869c2 940 }
amiraseman 23:a0ce9fa869c2 941
amiraseman 23:a0ce9fa869c2 942 }
amiraseman 23:a0ce9fa869c2 943
amiraseman 23:a0ce9fa869c2 944
amiraseman 23:a0ce9fa869c2 945
amiraseman 23:a0ce9fa869c2 946
amiraseman 23:a0ce9fa869c2 947
amiraseman 23:a0ce9fa869c2 948
amiraseman 23:a0ce9fa869c2 949
amiraseman 23:a0ce9fa869c2 950
amiraseman 23:a0ce9fa869c2 951
amiraseman 23:a0ce9fa869c2 952
amiraseman 23:a0ce9fa869c2 953
amiraseman 23:a0ce9fa869c2 954 /// Allows the user to set the power saving option and set the timeout
amiraseman 23:a0ce9fa869c2 955 void powerSaverSetting()
amiraseman 23:a0ce9fa869c2 956 {
amiraseman 23:a0ce9fa869c2 957
amiraseman 23:a0ce9fa869c2 958 state = powerSaverFlag ; //inits the state to the saved flag by the user in the past
amiraseman 23:a0ce9fa869c2 959 while (1) {
amiraseman 23:a0ce9fa869c2 960 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 961 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 962 updateTime();
amiraseman 23:a0ce9fa869c2 963 loggerData();
amiraseman 23:a0ce9fa869c2 964 sprintf (buffer0, " Back Save");
amiraseman 23:a0ce9fa869c2 965 sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 966 sprintf (buffer2, "Power Saver");
amiraseman 23:a0ce9fa869c2 967 sprintf (buffer3, ">>%s", fsmE[state].title);
amiraseman 23:a0ce9fa869c2 968 if (state == 1) {
amiraseman 23:a0ce9fa869c2 969 sprintf (buffer4, "%i mins", fsmE[state].output/60);
amiraseman 23:a0ce9fa869c2 970 } else { // if the power saver is off it dowsnt show the time
amiraseman 23:a0ce9fa869c2 971 sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 972 }
amiraseman 23:a0ce9fa869c2 973 sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 974
amiraseman 23:a0ce9fa869c2 975
amiraseman 23:a0ce9fa869c2 976 display();
amiraseman 23:a0ce9fa869c2 977
amiraseman 23:a0ce9fa869c2 978 powerSaverTime = fsmE[state].output; //sets the timer to to value of output from the fsm
amiraseman 23:a0ce9fa869c2 979 //serial.printf("Power Saver Time = %i \n powerSaverFlag = %i \n",powerSaverTime , powerSaverFlag);
amiraseman 23:a0ce9fa869c2 980
amiraseman 23:a0ce9fa869c2 981 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 982 button4Flag=0;
amiraseman 23:a0ce9fa869c2 983 fsmE[state].output += 60 ; //adds a minute to the timer when button 4 is pressed
amiraseman 23:a0ce9fa869c2 984 }
amiraseman 23:a0ce9fa869c2 985 if (fsmE[state].output > 600) { // maximum time is 10 minutes
amiraseman 23:a0ce9fa869c2 986 fsmE[state].output = 60 ;
amiraseman 23:a0ce9fa869c2 987 }
amiraseman 23:a0ce9fa869c2 988
amiraseman 23:a0ce9fa869c2 989 if (state > 1) {
amiraseman 23:a0ce9fa869c2 990 state = 0 ;
amiraseman 23:a0ce9fa869c2 991 }
amiraseman 23:a0ce9fa869c2 992
amiraseman 23:a0ce9fa869c2 993 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 994 button3Flag=0;
amiraseman 23:a0ce9fa869c2 995
amiraseman 23:a0ce9fa869c2 996 if (state== 1) {
amiraseman 23:a0ce9fa869c2 997 powerSaverTimeout.attach(&powerSaverExpired, powerSaverTime); // setup a timeiut to call the savePower function
amiraseman 23:a0ce9fa869c2 998 }
amiraseman 23:a0ce9fa869c2 999 break;
amiraseman 23:a0ce9fa869c2 1000 }
amiraseman 23:a0ce9fa869c2 1001
amiraseman 23:a0ce9fa869c2 1002
amiraseman 23:a0ce9fa869c2 1003 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 1004 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 1005 button1Flag=0;
amiraseman 23:a0ce9fa869c2 1006 state=fsmF[state].nextState[1];
amiraseman 23:a0ce9fa869c2 1007 }
amiraseman 23:a0ce9fa869c2 1008 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 1009 button2Flag=0;
amiraseman 23:a0ce9fa869c2 1010 state=fsmF[state].nextState[0];
amiraseman 23:a0ce9fa869c2 1011 }
amiraseman 23:a0ce9fa869c2 1012 }
amiraseman 23:a0ce9fa869c2 1013 }
amiraseman 23:a0ce9fa869c2 1014
amiraseman 23:a0ce9fa869c2 1015
amiraseman 23:a0ce9fa869c2 1016
amiraseman 23:a0ce9fa869c2 1017
amiraseman 23:a0ce9fa869c2 1018
amiraseman 23:a0ce9fa869c2 1019
amiraseman 23:a0ce9fa869c2 1020
amiraseman 23:a0ce9fa869c2 1021 /// Converts the entered raw date and time values by the user to create the unix time stamp
amiraseman 23:a0ce9fa869c2 1022 void calculateUNIXTime()
amiraseman 23:a0ce9fa869c2 1023 {
amiraseman 23:a0ce9fa869c2 1024
amiraseman 23:a0ce9fa869c2 1025 time_t rawtime;
amiraseman 23:a0ce9fa869c2 1026 struct tm * timeinfo;
amiraseman 23:a0ce9fa869c2 1027
amiraseman 23:a0ce9fa869c2 1028 // get current timeinfo
amiraseman 23:a0ce9fa869c2 1029 time ( &rawtime );
amiraseman 23:a0ce9fa869c2 1030 // convert to struct
amiraseman 23:a0ce9fa869c2 1031 timeinfo = localtime ( &rawtime );
amiraseman 23:a0ce9fa869c2 1032 // now modify the timeinfo to the given date
amiraseman 23:a0ce9fa869c2 1033 timeinfo->tm_year = (fsmC[4].output) - 1900;
amiraseman 23:a0ce9fa869c2 1034 timeinfo->tm_mon = (fsmC[3].output) - 1; //months since January - [0,11]
amiraseman 23:a0ce9fa869c2 1035 timeinfo->tm_mday = (fsmC[2].output) ; //day of the month - [1,31]
amiraseman 23:a0ce9fa869c2 1036 timeinfo->tm_hour = (fsmC[0].output) ; //hours since midnight - [0,23]
amiraseman 23:a0ce9fa869c2 1037 timeinfo->tm_min = (fsmC[1].output) ; //minutes after the hour - [0,59]
amiraseman 23:a0ce9fa869c2 1038 timeinfo->tm_sec = 0 ; //seconds after the minute - [0,59]
amiraseman 23:a0ce9fa869c2 1039
amiraseman 23:a0ce9fa869c2 1040 //call mktime to create unix time stamp from timeinfo struct
amiraseman 23:a0ce9fa869c2 1041 UNIXdate = mktime ( timeinfo );
amiraseman 23:a0ce9fa869c2 1042
amiraseman 23:a0ce9fa869c2 1043 }
amiraseman 23:a0ce9fa869c2 1044
amiraseman 23:a0ce9fa869c2 1045
amiraseman 23:a0ce9fa869c2 1046
amiraseman 23:a0ce9fa869c2 1047
amiraseman 23:a0ce9fa869c2 1048 /// Allows the user to change the units for temperature and pressure
amiraseman 23:a0ce9fa869c2 1049 void unitsSetting()
amiraseman 23:a0ce9fa869c2 1050 {
amiraseman 23:a0ce9fa869c2 1051 state = 0;
amiraseman 23:a0ce9fa869c2 1052 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 1053 while (1) {
amiraseman 23:a0ce9fa869c2 1054 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 1055 updateTime();
amiraseman 23:a0ce9fa869c2 1056 loggerData();
amiraseman 23:a0ce9fa869c2 1057
amiraseman 23:a0ce9fa869c2 1058 sprintf (buffer0, " Back Save");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1059 sprintf (buffer1, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1060 sprintf (buffer2, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1061 sprintf (buffer3, ">>%s", fsmD[state].title);//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1062 sprintf (buffer4, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1063 sprintf (buffer5, "");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1064
amiraseman 23:a0ce9fa869c2 1065
amiraseman 23:a0ce9fa869c2 1066 unitFlag = fsmD[state].output;
amiraseman 23:a0ce9fa869c2 1067
amiraseman 23:a0ce9fa869c2 1068 display();
amiraseman 23:a0ce9fa869c2 1069
amiraseman 23:a0ce9fa869c2 1070 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 1071 button3Flag=0;
amiraseman 23:a0ce9fa869c2 1072 state = 0;
amiraseman 23:a0ce9fa869c2 1073 break;
amiraseman 23:a0ce9fa869c2 1074 }
amiraseman 23:a0ce9fa869c2 1075
amiraseman 23:a0ce9fa869c2 1076 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 1077 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 1078 button1Flag=0;
amiraseman 23:a0ce9fa869c2 1079 state=fsmD[state].nextState[1];
amiraseman 23:a0ce9fa869c2 1080 }
amiraseman 23:a0ce9fa869c2 1081 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 1082 button2Flag=0;
amiraseman 23:a0ce9fa869c2 1083 state=fsmD[state].nextState[0];
amiraseman 23:a0ce9fa869c2 1084 }
amiraseman 23:a0ce9fa869c2 1085 }
amiraseman 23:a0ce9fa869c2 1086 }
amiraseman 23:a0ce9fa869c2 1087
amiraseman 23:a0ce9fa869c2 1088
amiraseman 23:a0ce9fa869c2 1089
amiraseman 23:a0ce9fa869c2 1090
amiraseman 23:a0ce9fa869c2 1091
amiraseman 23:a0ce9fa869c2 1092
amiraseman 23:a0ce9fa869c2 1093 /// Used by the user to set the current date and time
amiraseman 23:a0ce9fa869c2 1094 void timeDateSetting()
amiraseman 23:a0ce9fa869c2 1095 {
amiraseman 23:a0ce9fa869c2 1096
amiraseman 23:a0ce9fa869c2 1097 state = 0;
amiraseman 23:a0ce9fa869c2 1098 while (1) {
amiraseman 23:a0ce9fa869c2 1099 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 1100 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 1101 updateTime();
amiraseman 23:a0ce9fa869c2 1102 loggerData();
amiraseman 23:a0ce9fa869c2 1103
amiraseman 23:a0ce9fa869c2 1104 sprintf (buffer0, " Back Save");//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1105 sprintf (buffer1, "");
amiraseman 23:a0ce9fa869c2 1106 sprintf (buffer2, "");
amiraseman 23:a0ce9fa869c2 1107 sprintf (buffer3, ">>%s %d", fsmC[state].title,fsmC[state].output);//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1108 sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 1109 sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 1110
amiraseman 23:a0ce9fa869c2 1111
amiraseman 23:a0ce9fa869c2 1112 display();
amiraseman 23:a0ce9fa869c2 1113
amiraseman 23:a0ce9fa869c2 1114
amiraseman 23:a0ce9fa869c2 1115
amiraseman 23:a0ce9fa869c2 1116 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1117 button4Flag= 0;
amiraseman 23:a0ce9fa869c2 1118 fsmC[state].output ++;
amiraseman 23:a0ce9fa869c2 1119 calculateUNIXTime();
amiraseman 23:a0ce9fa869c2 1120 set_time(UNIXdate); // initialise time from the calculated UNIX time entered by the user
amiraseman 23:a0ce9fa869c2 1121 }
amiraseman 23:a0ce9fa869c2 1122
amiraseman 23:a0ce9fa869c2 1123
amiraseman 23:a0ce9fa869c2 1124 //checks the limits of the values
amiraseman 23:a0ce9fa869c2 1125 if (fsmC[0].output >23) { //hour
amiraseman 23:a0ce9fa869c2 1126 fsmC[0].output = 0 ;
amiraseman 23:a0ce9fa869c2 1127 }
amiraseman 23:a0ce9fa869c2 1128 if (fsmC[1].output>59) { // minute
amiraseman 23:a0ce9fa869c2 1129 fsmC[1].output = 0 ;
amiraseman 23:a0ce9fa869c2 1130 }
amiraseman 23:a0ce9fa869c2 1131 if (fsmC[3].output>11) { //month
amiraseman 23:a0ce9fa869c2 1132 fsmC[3].output = 0 ;
amiraseman 23:a0ce9fa869c2 1133 }
amiraseman 23:a0ce9fa869c2 1134 if (fsmC[2].output>31) { //day
amiraseman 23:a0ce9fa869c2 1135 fsmC[2].output = 1 ;
amiraseman 23:a0ce9fa869c2 1136 }
amiraseman 23:a0ce9fa869c2 1137 if (fsmC[4].output>2030) { //year
amiraseman 23:a0ce9fa869c2 1138 fsmC[4].output = 2015 ;
amiraseman 23:a0ce9fa869c2 1139 }
amiraseman 23:a0ce9fa869c2 1140
amiraseman 23:a0ce9fa869c2 1141
amiraseman 23:a0ce9fa869c2 1142
amiraseman 23:a0ce9fa869c2 1143 if (button3Flag) {
amiraseman 23:a0ce9fa869c2 1144 button3Flag=0;
amiraseman 23:a0ce9fa869c2 1145 state = 0;
amiraseman 23:a0ce9fa869c2 1146 break;
amiraseman 23:a0ce9fa869c2 1147 }
amiraseman 23:a0ce9fa869c2 1148 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 1149 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 1150 button1Flag=0;
amiraseman 23:a0ce9fa869c2 1151 state=fsmC[state].nextState[1];
amiraseman 23:a0ce9fa869c2 1152 }
amiraseman 23:a0ce9fa869c2 1153 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 1154 button2Flag=0;
amiraseman 23:a0ce9fa869c2 1155 state=fsmC[state].nextState[0];
amiraseman 23:a0ce9fa869c2 1156 }
amiraseman 23:a0ce9fa869c2 1157 }
amiraseman 23:a0ce9fa869c2 1158 }
amiraseman 23:a0ce9fa869c2 1159
amiraseman 23:a0ce9fa869c2 1160
amiraseman 23:a0ce9fa869c2 1161 /// The settings menu allows user to change the settings
amiraseman 23:a0ce9fa869c2 1162 void settingsMenu()
amiraseman 23:a0ce9fa869c2 1163 {
amiraseman 23:a0ce9fa869c2 1164 state = 0;
amiraseman 23:a0ce9fa869c2 1165 while(button3Flag==0) {
amiraseman 25:fa65a9cc78f0 1166 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 1167 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 1168 updateTime();
amiraseman 23:a0ce9fa869c2 1169 loggerData();
amiraseman 23:a0ce9fa869c2 1170 strncpy(buffer0, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 1171 int dispaly = sprintf (buffer1, "Settings");
amiraseman 23:a0ce9fa869c2 1172 int dispaly1 = sprintf (buffer2, "");
amiraseman 23:a0ce9fa869c2 1173 int dispaly2 = sprintf (buffer3, ">>%s", fsmB[state].title);//convert integer to buffer str
amiraseman 23:a0ce9fa869c2 1174 int dispaly3 = sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 1175 int dispaly4 = sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 1176
amiraseman 23:a0ce9fa869c2 1177 display();
amiraseman 23:a0ce9fa869c2 1178
amiraseman 23:a0ce9fa869c2 1179
amiraseman 23:a0ce9fa869c2 1180 switch (state) {
amiraseman 23:a0ce9fa869c2 1181 case 0:
amiraseman 23:a0ce9fa869c2 1182 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1183 button4Flag=0;
amiraseman 23:a0ce9fa869c2 1184 timeDateSetting();
amiraseman 23:a0ce9fa869c2 1185 }
amiraseman 23:a0ce9fa869c2 1186
amiraseman 23:a0ce9fa869c2 1187
amiraseman 23:a0ce9fa869c2 1188 break;
amiraseman 23:a0ce9fa869c2 1189 case 1:
amiraseman 23:a0ce9fa869c2 1190
amiraseman 23:a0ce9fa869c2 1191
amiraseman 23:a0ce9fa869c2 1192 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1193 button4Flag=0;
amiraseman 23:a0ce9fa869c2 1194 unitsSetting();
amiraseman 23:a0ce9fa869c2 1195 }
amiraseman 23:a0ce9fa869c2 1196
amiraseman 23:a0ce9fa869c2 1197 break;
amiraseman 23:a0ce9fa869c2 1198 case 2:
amiraseman 23:a0ce9fa869c2 1199
amiraseman 23:a0ce9fa869c2 1200 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1201 button4Flag = 0;
amiraseman 23:a0ce9fa869c2 1202 powerSaverSetting();
amiraseman 23:a0ce9fa869c2 1203 }
amiraseman 23:a0ce9fa869c2 1204 break;
amiraseman 23:a0ce9fa869c2 1205 case 3:
amiraseman 23:a0ce9fa869c2 1206 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1207 button4Flag = 0;
amiraseman 23:a0ce9fa869c2 1208 dataLoggerSetting();
amiraseman 23:a0ce9fa869c2 1209 }
amiraseman 23:a0ce9fa869c2 1210 break;
amiraseman 23:a0ce9fa869c2 1211 default:
amiraseman 23:a0ce9fa869c2 1212 break;
amiraseman 23:a0ce9fa869c2 1213 }
amiraseman 23:a0ce9fa869c2 1214 // if (button3Flag) {
amiraseman 23:a0ce9fa869c2 1215 // button3Flag=0;
amiraseman 23:a0ce9fa869c2 1216 // state = 0;
amiraseman 23:a0ce9fa869c2 1217 // break;
amiraseman 23:a0ce9fa869c2 1218 // }
amiraseman 23:a0ce9fa869c2 1219 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 1220 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 1221 button1Flag=0;
amiraseman 23:a0ce9fa869c2 1222 state=fsmB[state].nextState[1];
amiraseman 23:a0ce9fa869c2 1223 }
amiraseman 23:a0ce9fa869c2 1224 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 1225 button2Flag=0;
amiraseman 23:a0ce9fa869c2 1226 state=fsmB[state].nextState[0];
amiraseman 23:a0ce9fa869c2 1227 }
amiraseman 23:a0ce9fa869c2 1228 }
amiraseman 23:a0ce9fa869c2 1229 }
amiraseman 23:a0ce9fa869c2 1230
amiraseman 23:a0ce9fa869c2 1231 /// The first main menu
amiraseman 23:a0ce9fa869c2 1232 void startMenu()
amiraseman 23:a0ce9fa869c2 1233 {
amiraseman 23:a0ce9fa869c2 1234 while(1) {
amiraseman 23:a0ce9fa869c2 1235 updateTime();
amiraseman 23:a0ce9fa869c2 1236 alarmClockCheck();
amiraseman 23:a0ce9fa869c2 1237 powerSaverCheck();
amiraseman 23:a0ce9fa869c2 1238 loggerData();
amiraseman 23:a0ce9fa869c2 1239 button3Flag=0;
amiraseman 23:a0ce9fa869c2 1240 strncpy(buffer0, bufferTime, 14);
amiraseman 23:a0ce9fa869c2 1241 sprintf (buffer1, "Main Menu");
amiraseman 23:a0ce9fa869c2 1242 sprintf (buffer2, "");
amiraseman 23:a0ce9fa869c2 1243 sprintf (buffer3, ">>%s", fsmA[state].title);
amiraseman 23:a0ce9fa869c2 1244 sprintf (buffer4, "");
amiraseman 23:a0ce9fa869c2 1245 sprintf (buffer5, "");
amiraseman 23:a0ce9fa869c2 1246 display();
amiraseman 23:a0ce9fa869c2 1247
amiraseman 23:a0ce9fa869c2 1248
amiraseman 23:a0ce9fa869c2 1249 switch (state) {
amiraseman 23:a0ce9fa869c2 1250 case 0:
amiraseman 23:a0ce9fa869c2 1251 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1252 button4Flag=0;
amiraseman 23:a0ce9fa869c2 1253 liveData();
amiraseman 23:a0ce9fa869c2 1254 }
amiraseman 23:a0ce9fa869c2 1255 break;
amiraseman 23:a0ce9fa869c2 1256 case 1:
amiraseman 23:a0ce9fa869c2 1257 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1258 button4Flag=0;
amiraseman 23:a0ce9fa869c2 1259 dataLogger();
amiraseman 23:a0ce9fa869c2 1260 }
amiraseman 23:a0ce9fa869c2 1261 break;
amiraseman 23:a0ce9fa869c2 1262 case 2:
amiraseman 23:a0ce9fa869c2 1263 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1264 button4Flag=0;
amiraseman 23:a0ce9fa869c2 1265 alarmsMenu();
amiraseman 23:a0ce9fa869c2 1266 }
amiraseman 23:a0ce9fa869c2 1267 break;
amiraseman 23:a0ce9fa869c2 1268 case 3:
amiraseman 23:a0ce9fa869c2 1269 if (button4Flag) {
amiraseman 23:a0ce9fa869c2 1270 button4Flag=0;
amiraseman 23:a0ce9fa869c2 1271 settingsMenu();
amiraseman 23:a0ce9fa869c2 1272 }
amiraseman 23:a0ce9fa869c2 1273 break;
amiraseman 23:a0ce9fa869c2 1274 default:
amiraseman 23:a0ce9fa869c2 1275 break;
amiraseman 23:a0ce9fa869c2 1276 }
amiraseman 23:a0ce9fa869c2 1277
amiraseman 23:a0ce9fa869c2 1278
amiraseman 23:a0ce9fa869c2 1279 //Navigates to the next5 state of the fsm when one of the buttons is pressed
amiraseman 23:a0ce9fa869c2 1280 if (button1Flag == 1) {
amiraseman 23:a0ce9fa869c2 1281 button1Flag=0;
amiraseman 23:a0ce9fa869c2 1282 state=fsmA[state].nextState[1];
amiraseman 23:a0ce9fa869c2 1283 }
amiraseman 23:a0ce9fa869c2 1284 if (button2Flag == 1) {
amiraseman 23:a0ce9fa869c2 1285 button2Flag=0;
amiraseman 23:a0ce9fa869c2 1286 state=fsmA[state].nextState[0];
amiraseman 23:a0ce9fa869c2 1287 }
amiraseman 23:a0ce9fa869c2 1288
amiraseman 23:a0ce9fa869c2 1289 }
amiraseman 23:a0ce9fa869c2 1290 }
amiraseman 23:a0ce9fa869c2 1291
amiraseman 23:a0ce9fa869c2 1292
amiraseman 23:a0ce9fa869c2 1293
amiraseman 23:a0ce9fa869c2 1294
amiraseman 23:a0ce9fa869c2 1295 int main()
amiraseman 23:a0ce9fa869c2 1296 {
amiraseman 23:a0ce9fa869c2 1297
amiraseman 23:a0ce9fa869c2 1298 /// Initialise barometer
amiraseman 23:a0ce9fa869c2 1299 bmp180.init();
amiraseman 23:a0ce9fa869c2 1300 /// Initialise the lcd
amiraseman 23:a0ce9fa869c2 1301 lcd.init();
amiraseman 23:a0ce9fa869c2 1302 /// call the appropriate ISR on rising edge (when any of the buttons are pressed)
amiraseman 23:a0ce9fa869c2 1303 button1.rise(&button1Pressed);
amiraseman 23:a0ce9fa869c2 1304 button2.rise(&button2Pressed);
amiraseman 23:a0ce9fa869c2 1305 button3.rise(&button3Pressed);
amiraseman 23:a0ce9fa869c2 1306 button4.rise(&button4Pressed);
amiraseman 23:a0ce9fa869c2 1307 debounce.start();
amiraseman 23:a0ce9fa869c2 1308 /// Set frequency at 40kHz for the leds
amiraseman 23:a0ce9fa869c2 1309 redLED.period_us(25);
amiraseman 23:a0ce9fa869c2 1310 yellowLED.period_us(25);
amiraseman 23:a0ce9fa869c2 1311 greenLED.period_us(25);
amiraseman 23:a0ce9fa869c2 1312 state = 0;
amiraseman 23:a0ce9fa869c2 1313 startMenu();
amiraseman 23:a0ce9fa869c2 1314 }
amiraseman 23:a0ce9fa869c2 1315
amiraseman 23:a0ce9fa869c2 1316
amiraseman 23:a0ce9fa869c2 1317