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 10:12:22 2015 +0000
Revision:
26:c0d8d2f68406
Parent:
25:fa65a9cc78f0
Child:
27:06fbad36c15e
layout finalised;

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