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

Dependencies:   BMP180 N5110 PowerControl mbed

Committer:
amiraseman
Date:
Sat May 09 01:24:06 2015 +0000
Revision:
24:51cbed3fbf5c
Parent:
23:a0ce9fa869c2
Child:
25:fa65a9cc78f0
solved the problem with thresholds;

Who changed what in which revision?

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