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:
Mon May 11 22:10:42 2015 +0000
Revision:
27:06fbad36c15e
Parent:
26:c0d8d2f68406
Final Commit;

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