ELEC2645 Year 2 Project Arnau Segura Doncel 200867010

Dependencies:   N5110 SRF02 TMP102 mbed

Committer:
ollie140
Date:
Thu May 05 09:41:14 2016 +0000
Revision:
0:4a66fd16c223
Final code for the level 2 year project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ollie140 0:4a66fd16c223 1 /**
ollie140 0:4a66fd16c223 2 @file main.cpp
ollie140 0:4a66fd16c223 3 @brief program implementation
ollie140 0:4a66fd16c223 4
ollie140 0:4a66fd16c223 5 */
ollie140 0:4a66fd16c223 6 #include "main.h"
ollie140 0:4a66fd16c223 7
ollie140 0:4a66fd16c223 8 int main()
ollie140 0:4a66fd16c223 9 {
ollie140 0:4a66fd16c223 10 introScreen();
ollie140 0:4a66fd16c223 11 while (1) {
ollie140 0:4a66fd16c223 12 if (g_timer2_flag) {
ollie140 0:4a66fd16c223 13 g_timer2_flag = 0;
ollie140 0:4a66fd16c223 14 if (current_screen == menu_state) { //Main menu
ollie140 0:4a66fd16c223 15 mainMenu();
ollie140 0:4a66fd16c223 16 } else if (current_screen == modes_state) { //modes menu
ollie140 0:4a66fd16c223 17 modesMenu();
ollie140 0:4a66fd16c223 18 } else if (current_screen == peripherals_state) { // peripherals menu
ollie140 0:4a66fd16c223 19 peripheralsMenu();
ollie140 0:4a66fd16c223 20 } else if (current_screen == brightness_state) { // brightness menu
ollie140 0:4a66fd16c223 21 brightnessMenu();
ollie140 0:4a66fd16c223 22 } else if (current_screen == sound_state) { // sound menu
ollie140 0:4a66fd16c223 23 soundMenu();
ollie140 0:4a66fd16c223 24 } else if (current_screen == ledMenu_state) { // LED menu
ollie140 0:4a66fd16c223 25 LEDMenu();
ollie140 0:4a66fd16c223 26 } else if (current_screen == nightMenu_state) { // night menu
ollie140 0:4a66fd16c223 27 nightMenu();
ollie140 0:4a66fd16c223 28 } else if (current_screen == parkingMode_state) { // parking mode setup
ollie140 0:4a66fd16c223 29 printBars();
ollie140 0:4a66fd16c223 30 } else if (current_screen == numericMode_state) { // numeric mode setup
ollie140 0:4a66fd16c223 31 numericMode();
ollie140 0:4a66fd16c223 32 }
ollie140 0:4a66fd16c223 33 }
ollie140 0:4a66fd16c223 34 sleep();
ollie140 0:4a66fd16c223 35 }
ollie140 0:4a66fd16c223 36 }
ollie140 0:4a66fd16c223 37
ollie140 0:4a66fd16c223 38
ollie140 0:4a66fd16c223 39 float getDistance()
ollie140 0:4a66fd16c223 40 {
ollie140 0:4a66fd16c223 41
ollie140 0:4a66fd16c223 42 emptyVariable = 0; // initialise the empty variable
ollie140 0:4a66fd16c223 43
ollie140 0:4a66fd16c223 44 for (int i = 0 ; i<10; i++) { // intitialises the measurement for loop
ollie140 0:4a66fd16c223 45
ollie140 0:4a66fd16c223 46 realDistance = srf.getDistanceCm(); // get a distance measurement for every i value
ollie140 0:4a66fd16c223 47 emptyVariable = emptyVariable + realDistance ; // add all these measurements up
ollie140 0:4a66fd16c223 48 }
ollie140 0:4a66fd16c223 49
ollie140 0:4a66fd16c223 50 distance = emptyVariable/10.0; // divide all the measurements by 10 to take the average
ollie140 0:4a66fd16c223 51 return distance; // return the distance
ollie140 0:4a66fd16c223 52
ollie140 0:4a66fd16c223 53 }
ollie140 0:4a66fd16c223 54
ollie140 0:4a66fd16c223 55 void drawCar()
ollie140 0:4a66fd16c223 56 {
ollie140 0:4a66fd16c223 57 lcd.drawRect(1,8,56,32,1); // main car rectangle
ollie140 0:4a66fd16c223 58 lcd.drawRect(15,6,9,1,1); // right front wheel
ollie140 0:4a66fd16c223 59 lcd.drawRect(40,6,9,1,1); // right back wheel
ollie140 0:4a66fd16c223 60 lcd.drawRect(15,41,9,1,1); // left front wheel
ollie140 0:4a66fd16c223 61 lcd.drawRect(40,41,9,1,1); // left back wheel
ollie140 0:4a66fd16c223 62 lcd.drawRect(20,14,9,20,2); // front window
ollie140 0:4a66fd16c223 63 lcd.drawRect(42,16,6,16,2); // back window
ollie140 0:4a66fd16c223 64
ollie140 0:4a66fd16c223 65 }
ollie140 0:4a66fd16c223 66
ollie140 0:4a66fd16c223 67 void reallyCloseDistance()
ollie140 0:4a66fd16c223 68 {
ollie140 0:4a66fd16c223 69 lcd.drawRect(60,8,3,32,1); // really close bar
ollie140 0:4a66fd16c223 70 lcd.drawRect(66,8,3,32,1); // close bar
ollie140 0:4a66fd16c223 71 lcd.drawRect(72,8,3,32,1); // medium bar
ollie140 0:4a66fd16c223 72 lcd.drawRect(78,8,3,32,1); // far bar
ollie140 0:4a66fd16c223 73 }
ollie140 0:4a66fd16c223 74
ollie140 0:4a66fd16c223 75 void closeDistance()
ollie140 0:4a66fd16c223 76 {
ollie140 0:4a66fd16c223 77 lcd.drawRect(66,8,3,32,1); // close bar
ollie140 0:4a66fd16c223 78 lcd.drawRect(72,8,3,32,1); // medium bar
ollie140 0:4a66fd16c223 79 lcd.drawRect(78,8,3,32,1); // far bar
ollie140 0:4a66fd16c223 80 }
ollie140 0:4a66fd16c223 81
ollie140 0:4a66fd16c223 82 void mediumDistance()
ollie140 0:4a66fd16c223 83 {
ollie140 0:4a66fd16c223 84 lcd.drawRect(72,8,3,32,1); // medium bar
ollie140 0:4a66fd16c223 85 lcd.drawRect(78,8,3,32,1); // far bar
ollie140 0:4a66fd16c223 86 }
ollie140 0:4a66fd16c223 87
ollie140 0:4a66fd16c223 88 void farDistance()
ollie140 0:4a66fd16c223 89 {
ollie140 0:4a66fd16c223 90 lcd.drawRect(78,8,3,32,1); // far bar
ollie140 0:4a66fd16c223 91 }
ollie140 0:4a66fd16c223 92
ollie140 0:4a66fd16c223 93 void printBars()
ollie140 0:4a66fd16c223 94 {
ollie140 0:4a66fd16c223 95 potTicker.detach(); // detach the potentiometer ticker
ollie140 0:4a66fd16c223 96
ollie140 0:4a66fd16c223 97 sensorTicker.attach(&timer_isr,0.7); // attach a ticker that will be called every 0.7 seconds
ollie140 0:4a66fd16c223 98
ollie140 0:4a66fd16c223 99 while (current_screen == parkingMode_state) { // while the parking mode menu is true
ollie140 0:4a66fd16c223 100
ollie140 0:4a66fd16c223 101 dist = getDistance(); // get the distance in cm
ollie140 0:4a66fd16c223 102
ollie140 0:4a66fd16c223 103 T = tmp102.get_temperature(); // get the temperature in C
ollie140 0:4a66fd16c223 104
ollie140 0:4a66fd16c223 105 temp = floor(T); // floor the temperature to get an integer value
ollie140 0:4a66fd16c223 106
ollie140 0:4a66fd16c223 107 LED = 0; // Set the LED to off
ollie140 0:4a66fd16c223 108
ollie140 0:4a66fd16c223 109 if (g_timer_flag) { // if the timer event is called
ollie140 0:4a66fd16c223 110
ollie140 0:4a66fd16c223 111 g_timer_flag = 0; // reset flag back to 0
ollie140 0:4a66fd16c223 112
ollie140 0:4a66fd16c223 113 lcd.clear();// clear the screen
ollie140 0:4a66fd16c223 114
ollie140 0:4a66fd16c223 115 length2 = sprintf(buffer2,"%dC",temp); // assign a value to the string lenght
ollie140 0:4a66fd16c223 116
ollie140 0:4a66fd16c223 117 if (length2 <= 14) { // if string will fit on display
ollie140 0:4a66fd16c223 118 lcd.printString(buffer2,66,0); // print the desired string
ollie140 0:4a66fd16c223 119 }
ollie140 0:4a66fd16c223 120
ollie140 0:4a66fd16c223 121 if (dist > 140) { // if distance is more than 140 cm
ollie140 0:4a66fd16c223 122 drawCar(); // draw the car shape
ollie140 0:4a66fd16c223 123 buzzerOFF();
ollie140 0:4a66fd16c223 124 } else if (dist <= 140 && dist > 100) { // if distance is between 140 cm and 100 cm
ollie140 0:4a66fd16c223 125 drawCar(); // draw the car shape
ollie140 0:4a66fd16c223 126 farDistance(); // draw 1 bar
ollie140 0:4a66fd16c223 127 buzzerOFF();
ollie140 0:4a66fd16c223 128 } else if (dist <= 100 && dist > 70) { // if distance is between 100 cm and 70 cm
ollie140 0:4a66fd16c223 129 drawCar(); // draw the car shape
ollie140 0:4a66fd16c223 130 mediumDistance(); // draw 2 bars
ollie140 0:4a66fd16c223 131 buzzerOFF();
ollie140 0:4a66fd16c223 132 } else if (dist <= 70 && dist > 40) { // if distance is between 70 cm and 40 cm
ollie140 0:4a66fd16c223 133 drawCar(); // draw the car shape
ollie140 0:4a66fd16c223 134 closeDistance(); // draw 3 bars
ollie140 0:4a66fd16c223 135 buzzerOFF();
ollie140 0:4a66fd16c223 136 } else { // if distance is less than 40 cm
ollie140 0:4a66fd16c223 137 drawCar(); // draw the car shape
ollie140 0:4a66fd16c223 138 reallyCloseDistance(); // draw 4 bars
ollie140 0:4a66fd16c223 139
ollie140 0:4a66fd16c223 140 if (buzzer_state == buzzerON_state) {
ollie140 0:4a66fd16c223 141 buzzerON();
ollie140 0:4a66fd16c223 142 } else {
ollie140 0:4a66fd16c223 143 buzzerOFF();
ollie140 0:4a66fd16c223 144 }
ollie140 0:4a66fd16c223 145
ollie140 0:4a66fd16c223 146 if (led_state == LEDON_state) { // if the state of the LED menu is on
ollie140 0:4a66fd16c223 147 LED = 1; // turn on the LED
ollie140 0:4a66fd16c223 148 } else {
ollie140 0:4a66fd16c223 149 LED = 0; // keep the LED off
ollie140 0:4a66fd16c223 150 }
ollie140 0:4a66fd16c223 151 }
ollie140 0:4a66fd16c223 152
ollie140 0:4a66fd16c223 153 if (g_botButton_flag) { // if the button is pressed
ollie140 0:4a66fd16c223 154 g_botButton_flag = 0; // reset the flag
ollie140 0:4a66fd16c223 155
ollie140 0:4a66fd16c223 156 LED = 0; // turn off the LED
ollie140 0:4a66fd16c223 157
ollie140 0:4a66fd16c223 158 buzzerOFF(); // sets the duty cycle to 0
ollie140 0:4a66fd16c223 159
ollie140 0:4a66fd16c223 160 sensorTicker.detach(); // detach the sensor ticker to save computing powr and battery
ollie140 0:4a66fd16c223 161
ollie140 0:4a66fd16c223 162 current_screen = menu_state; // go back to the main menu
ollie140 0:4a66fd16c223 163
ollie140 0:4a66fd16c223 164 potTicker.attach(&timer2_isr,0.2); // attach the potentiometer ticker
ollie140 0:4a66fd16c223 165
ollie140 0:4a66fd16c223 166 }
ollie140 0:4a66fd16c223 167 lcd.refresh(); // refresh the screen
ollie140 0:4a66fd16c223 168 }
ollie140 0:4a66fd16c223 169 sleep(); // send the MCU back to sleep to save power
ollie140 0:4a66fd16c223 170 }
ollie140 0:4a66fd16c223 171
ollie140 0:4a66fd16c223 172 }
ollie140 0:4a66fd16c223 173
ollie140 0:4a66fd16c223 174 void numericMode()
ollie140 0:4a66fd16c223 175 {
ollie140 0:4a66fd16c223 176 potTicker.detach(); // detanch the ticker potentiometer
ollie140 0:4a66fd16c223 177
ollie140 0:4a66fd16c223 178 sensorTicker.attach(&timer_isr,0.7); // attach the sensor ticker to be called every 0.7 seconds
ollie140 0:4a66fd16c223 179
ollie140 0:4a66fd16c223 180 while (current_screen == numericMode_state) {
ollie140 0:4a66fd16c223 181
ollie140 0:4a66fd16c223 182 dist = getDistance(); // get the distance in cm
ollie140 0:4a66fd16c223 183
ollie140 0:4a66fd16c223 184 T = tmp102.get_temperature(); // get the temperature in C
ollie140 0:4a66fd16c223 185
ollie140 0:4a66fd16c223 186 if (g_timer_flag) { // if time event is triggered
ollie140 0:4a66fd16c223 187
ollie140 0:4a66fd16c223 188 lcd.clear(); // clear the LCD
ollie140 0:4a66fd16c223 189
ollie140 0:4a66fd16c223 190 length1 = sprintf(buffer,"D = %.2f cm",dist); // assign a lenght integer for the distance string
ollie140 0:4a66fd16c223 191
ollie140 0:4a66fd16c223 192 length2 = sprintf(buffer2,"T = %.2f C",T); // assign a lenght integer for the temperature string
ollie140 0:4a66fd16c223 193
ollie140 0:4a66fd16c223 194 if (length1 <= 14) { // if string will fit on display
ollie140 0:4a66fd16c223 195 lcd.printString(buffer,0,2);
ollie140 0:4a66fd16c223 196 }
ollie140 0:4a66fd16c223 197 if (length2 <= 14) { // if string will fit on display
ollie140 0:4a66fd16c223 198 lcd.printString(buffer2,0,4);
ollie140 0:4a66fd16c223 199 }
ollie140 0:4a66fd16c223 200
ollie140 0:4a66fd16c223 201 if (g_botButton_flag) { // if the event trigger is activated by pressing the bottom button
ollie140 0:4a66fd16c223 202 g_botButton_flag = 0; // reset the flag
ollie140 0:4a66fd16c223 203
ollie140 0:4a66fd16c223 204 sensorTicker.detach(); // detach the sensor ticker
ollie140 0:4a66fd16c223 205
ollie140 0:4a66fd16c223 206 current_screen = menu_state; // go back to the main menu
ollie140 0:4a66fd16c223 207
ollie140 0:4a66fd16c223 208 potTicker.attach(&timer2_isr,0.2); // attach the potentiometer ticker
ollie140 0:4a66fd16c223 209
ollie140 0:4a66fd16c223 210 }
ollie140 0:4a66fd16c223 211
ollie140 0:4a66fd16c223 212 lcd.refresh(); // refresh the LCD
ollie140 0:4a66fd16c223 213 }
ollie140 0:4a66fd16c223 214 sleep(); // save power by sending the MCU to sleep
ollie140 0:4a66fd16c223 215 }
ollie140 0:4a66fd16c223 216 }
ollie140 0:4a66fd16c223 217
ollie140 0:4a66fd16c223 218
ollie140 0:4a66fd16c223 219 void introScreen()
ollie140 0:4a66fd16c223 220 {
ollie140 0:4a66fd16c223 221
ollie140 0:4a66fd16c223 222 init_K64F(); // intialise all of the K64F's on board peripherals
ollie140 0:4a66fd16c223 223 init_serial();
ollie140 0:4a66fd16c223 224 potTicker.attach(&timer2_isr,0.2); // attach a ticker for the potentiometer
ollie140 0:4a66fd16c223 225 tmp102.init(); // initialise the temperature sensor
ollie140 0:4a66fd16c223 226 lcd.init(); // initialise the LCD display
ollie140 0:4a66fd16c223 227 lcd.setBrightness(1.0);
ollie140 0:4a66fd16c223 228 lcd.printString("PARKING",21,0);
ollie140 0:4a66fd16c223 229 lcd.printString("SENSOR",25,2);
ollie140 0:4a66fd16c223 230 lcd.printString("BY",36,3);
ollie140 0:4a66fd16c223 231 lcd.printString("ARNAU SEGURA",6,4);
ollie140 0:4a66fd16c223 232 led_state = LEDON_state; // start with the warning LED on the ON state
ollie140 0:4a66fd16c223 233 buzzer.period(1/1000.0);
ollie140 0:4a66fd16c223 234 buzzer_state = buzzerON_state;
ollie140 0:4a66fd16c223 235 wait(3); // wait 3 seconds
ollie140 0:4a66fd16c223 236 lcd.clear(); // clear the LCD
ollie140 0:4a66fd16c223 237 lcd.refresh(); // refresh the LCD
ollie140 0:4a66fd16c223 238
ollie140 0:4a66fd16c223 239 }
ollie140 0:4a66fd16c223 240
ollie140 0:4a66fd16c223 241 void mainMenu()
ollie140 0:4a66fd16c223 242 {
ollie140 0:4a66fd16c223 243
ollie140 0:4a66fd16c223 244 lcd.clear(); // clear the LCD
ollie140 0:4a66fd16c223 245 lcd.printString("MENU",28,0);
ollie140 0:4a66fd16c223 246 lcd.printString("MODES",25,2);
ollie140 0:4a66fd16c223 247 lcd.printString("PERIPHERALS",9,4);
ollie140 0:4a66fd16c223 248
ollie140 0:4a66fd16c223 249 g_botButton_flag = 0; // set the flag to 0 on the main menu so that if the bottom button is accidentally pressed the bug where the user would be forced to stay in main menu is solved
ollie140 0:4a66fd16c223 250
ollie140 0:4a66fd16c223 251 if (pot < 0.5f) { // if the potentiometer is normalised to less than 0.5
ollie140 0:4a66fd16c223 252 MenuLine2(); // invert pixels in bank 3
ollie140 0:4a66fd16c223 253 selected_option = modes_state;
ollie140 0:4a66fd16c223 254 } else {
ollie140 0:4a66fd16c223 255 MenuLine4(); // invert pixels in bank 5
ollie140 0:4a66fd16c223 256 selected_option = peripherals_state;
ollie140 0:4a66fd16c223 257 }
ollie140 0:4a66fd16c223 258 goToSelectedOption(); // if the top button is pressed go to the selected option
ollie140 0:4a66fd16c223 259 lcd.refresh();
ollie140 0:4a66fd16c223 260 }
ollie140 0:4a66fd16c223 261
ollie140 0:4a66fd16c223 262 void peripheralsMenu()
ollie140 0:4a66fd16c223 263 {
ollie140 0:4a66fd16c223 264 lcd.clear();
ollie140 0:4a66fd16c223 265 lcd.printString("PERIPHERALS",9,0);
ollie140 0:4a66fd16c223 266 lcd.printString("BRIGHTNESS",12,2);
ollie140 0:4a66fd16c223 267 lcd.printString("SOUND",25,3);
ollie140 0:4a66fd16c223 268 lcd.printString("LEDs",28,4);
ollie140 0:4a66fd16c223 269 lcd.printString("NIGHT LCD",15,5);
ollie140 0:4a66fd16c223 270 if (pot <= 0.25f) {
ollie140 0:4a66fd16c223 271 MenuLine2(); // invert pixels in bank 3
ollie140 0:4a66fd16c223 272 selected_option = brightness_state;
ollie140 0:4a66fd16c223 273 } else if (pot <= 0.5f) {
ollie140 0:4a66fd16c223 274 MenuLine3(); // invert pixels in bank 4
ollie140 0:4a66fd16c223 275 selected_option = sound_state;
ollie140 0:4a66fd16c223 276 } else if (pot <= 0.75f) {
ollie140 0:4a66fd16c223 277 MenuLine4(); // invert pixels in bank 5
ollie140 0:4a66fd16c223 278 selected_option = ledMenu_state;
ollie140 0:4a66fd16c223 279 } else {
ollie140 0:4a66fd16c223 280 MenuLine5(); // invert pixels in bank 6
ollie140 0:4a66fd16c223 281 selected_option = nightMenu_state;
ollie140 0:4a66fd16c223 282 }
ollie140 0:4a66fd16c223 283 goToMainMenu(); // if bottom button is pressed go back to main menu
ollie140 0:4a66fd16c223 284 goToSelectedOption(); // if the top button is pressed go to the selected option
ollie140 0:4a66fd16c223 285 lcd.refresh();
ollie140 0:4a66fd16c223 286 }
ollie140 0:4a66fd16c223 287
ollie140 0:4a66fd16c223 288 void modesMenu()
ollie140 0:4a66fd16c223 289 {
ollie140 0:4a66fd16c223 290 lcd.clear();
ollie140 0:4a66fd16c223 291 lcd.printString("MODES",25,0);
ollie140 0:4a66fd16c223 292 lcd.printString("PARKING MODE",6,2);
ollie140 0:4a66fd16c223 293 lcd.printString("NUMERIC MODE",6,4);
ollie140 0:4a66fd16c223 294
ollie140 0:4a66fd16c223 295 if (pot <= 0.5f) {
ollie140 0:4a66fd16c223 296 MenuLine2(); // invert pixels in bank 3
ollie140 0:4a66fd16c223 297 selected_option = parkingMode_state;
ollie140 0:4a66fd16c223 298 } else {
ollie140 0:4a66fd16c223 299 MenuLine4(); // invert pixels in bank 5
ollie140 0:4a66fd16c223 300 selected_option = numericMode_state;
ollie140 0:4a66fd16c223 301 }
ollie140 0:4a66fd16c223 302 goToMainMenu(); // go back to main menu
ollie140 0:4a66fd16c223 303 goToSelectedOption(); // go to selected option
ollie140 0:4a66fd16c223 304 lcd.refresh();
ollie140 0:4a66fd16c223 305 }
ollie140 0:4a66fd16c223 306
ollie140 0:4a66fd16c223 307 void soundMenu()
ollie140 0:4a66fd16c223 308 {
ollie140 0:4a66fd16c223 309 lcd.clear();
ollie140 0:4a66fd16c223 310 lcd.printString("SOUND MENU",12,0);
ollie140 0:4a66fd16c223 311 lcd.printString("SOUND ON",18,3);
ollie140 0:4a66fd16c223 312 lcd.printString("SOUND OFF",15,5);
ollie140 0:4a66fd16c223 313
ollie140 0:4a66fd16c223 314 if (pot <= 0.5f) {
ollie140 0:4a66fd16c223 315 MenuLine3Short(); // partially inverts bank 4 of the LCD
ollie140 0:4a66fd16c223 316 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 317 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 318
ollie140 0:4a66fd16c223 319 buzzer_state = buzzerON_state;
ollie140 0:4a66fd16c223 320 circle_position_SOUND = 27; // set y position for the circle to be drawed
ollie140 0:4a66fd16c223 321 }
ollie140 0:4a66fd16c223 322 } else {
ollie140 0:4a66fd16c223 323 MenuLine5Short(); // partially inverts bank 6 of the LCD
ollie140 0:4a66fd16c223 324 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 325 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 326
ollie140 0:4a66fd16c223 327 buzzer_state = buzzerOFF_state;
ollie140 0:4a66fd16c223 328 circle_position_SOUND = 43; // set y position for the circle to be drawed
ollie140 0:4a66fd16c223 329 }
ollie140 0:4a66fd16c223 330 }
ollie140 0:4a66fd16c223 331
ollie140 0:4a66fd16c223 332 lcd.drawCircle(4,circle_position_SOUND,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 333 lcd.drawCircle(80,circle_position_SOUND,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 334 goToMainMenu(); // go back to main menu
ollie140 0:4a66fd16c223 335 lcd.refresh();
ollie140 0:4a66fd16c223 336 }
ollie140 0:4a66fd16c223 337
ollie140 0:4a66fd16c223 338 void buzzerON()
ollie140 0:4a66fd16c223 339 {
ollie140 0:4a66fd16c223 340 buzzer.write(0.5); // set the buzzers duty cycle to 50%
ollie140 0:4a66fd16c223 341 }
ollie140 0:4a66fd16c223 342
ollie140 0:4a66fd16c223 343 void buzzerOFF()
ollie140 0:4a66fd16c223 344 {
ollie140 0:4a66fd16c223 345 buzzer.write(0.0); // set the buzzers duty cycle to 0%
ollie140 0:4a66fd16c223 346 }
ollie140 0:4a66fd16c223 347
ollie140 0:4a66fd16c223 348 void LEDMenu()
ollie140 0:4a66fd16c223 349 {
ollie140 0:4a66fd16c223 350
ollie140 0:4a66fd16c223 351 lcd.clear();
ollie140 0:4a66fd16c223 352 lcd.printString("LED MENU",18,0);
ollie140 0:4a66fd16c223 353 lcd.printString("LED ON",24,3);
ollie140 0:4a66fd16c223 354 lcd.printString("LED OFF",21,5);
ollie140 0:4a66fd16c223 355
ollie140 0:4a66fd16c223 356 if (pot <= 0.5f) {
ollie140 0:4a66fd16c223 357 MenuLine3Short(); // partially inverts bank 4 of the LCD
ollie140 0:4a66fd16c223 358 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 359 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 360
ollie140 0:4a66fd16c223 361 circle_position_LED = 27; // set y position for the circle to be drawn
ollie140 0:4a66fd16c223 362 led_state = LEDON_state; // set the empty led state variable to the LED On state
ollie140 0:4a66fd16c223 363 }
ollie140 0:4a66fd16c223 364
ollie140 0:4a66fd16c223 365 } else {
ollie140 0:4a66fd16c223 366 MenuLine5Short(); // partially inverts bank 6 of the LCD
ollie140 0:4a66fd16c223 367 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 368 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 369
ollie140 0:4a66fd16c223 370 circle_position_LED = 43; // set y position for the circle to be drawn
ollie140 0:4a66fd16c223 371 led_state = LEDOFF_state; // set the empty led state variable to the LED Off state
ollie140 0:4a66fd16c223 372 }
ollie140 0:4a66fd16c223 373 }
ollie140 0:4a66fd16c223 374
ollie140 0:4a66fd16c223 375 lcd.drawCircle(4,circle_position_LED,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 376 lcd.drawCircle(80,circle_position_LED,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 377 goToMainMenu(); // go to main menu
ollie140 0:4a66fd16c223 378 lcd.refresh();
ollie140 0:4a66fd16c223 379
ollie140 0:4a66fd16c223 380 }
ollie140 0:4a66fd16c223 381
ollie140 0:4a66fd16c223 382 void brightnessMenu()
ollie140 0:4a66fd16c223 383 {
ollie140 0:4a66fd16c223 384 lcd.clear();
ollie140 0:4a66fd16c223 385 lcd.printString("BRIGHTNESS",12,0);
ollie140 0:4a66fd16c223 386 lcd.printString("0%",36,1);
ollie140 0:4a66fd16c223 387 lcd.printString("25%",33,2);
ollie140 0:4a66fd16c223 388 lcd.printString("50%",33,3);
ollie140 0:4a66fd16c223 389 lcd.printString("75%",33,4);
ollie140 0:4a66fd16c223 390 lcd.printString("100%",30,5);
ollie140 0:4a66fd16c223 391
ollie140 0:4a66fd16c223 392 if (pot <= 0.2f) {
ollie140 0:4a66fd16c223 393 MenuLine1Short(); // partially inverts bank 2 of the LCD
ollie140 0:4a66fd16c223 394 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 395 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 396 circle_position_brightness = 11; // set y position for circle
ollie140 0:4a66fd16c223 397 screenLED.write(0.0); // set the brighness to 0%
ollie140 0:4a66fd16c223 398 }
ollie140 0:4a66fd16c223 399 } else if (pot <= 0.4f) {
ollie140 0:4a66fd16c223 400 MenuLine2Short(); // partially inverts bank 3 of the LCD
ollie140 0:4a66fd16c223 401 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 402 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 403 circle_position_brightness = 19; // set y position for circle
ollie140 0:4a66fd16c223 404 screenLED.write(0.25); // set the brighness to 25%
ollie140 0:4a66fd16c223 405 }
ollie140 0:4a66fd16c223 406 } else if (pot <= 0.6f) {
ollie140 0:4a66fd16c223 407 MenuLine3Short(); // partially inverts bank 4 of the LCD
ollie140 0:4a66fd16c223 408 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 409 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 410 circle_position_brightness = 27; // set y position for circle
ollie140 0:4a66fd16c223 411 screenLED.write(0.5); // set the brighness to 50%
ollie140 0:4a66fd16c223 412 }
ollie140 0:4a66fd16c223 413 } else if (pot <= 0.8f) {
ollie140 0:4a66fd16c223 414 MenuLine4Short(); // partially inverts bank 5 of the LCD
ollie140 0:4a66fd16c223 415 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 416 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 417 circle_position_brightness = 35; // set y position for circle
ollie140 0:4a66fd16c223 418 screenLED.write(0.75); // set the brighness to 75%
ollie140 0:4a66fd16c223 419 }
ollie140 0:4a66fd16c223 420 } else {
ollie140 0:4a66fd16c223 421 MenuLine5Short(); // partially inverts bank 6 of the LCD
ollie140 0:4a66fd16c223 422 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 423 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 424 circle_position_brightness = 43; // set y position for circle
ollie140 0:4a66fd16c223 425 screenLED.write(1.0); // set the brighness to 100%
ollie140 0:4a66fd16c223 426 }
ollie140 0:4a66fd16c223 427 }
ollie140 0:4a66fd16c223 428
ollie140 0:4a66fd16c223 429 lcd.drawCircle(4,circle_position_brightness,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 430 lcd.drawCircle(80,circle_position_brightness,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 431 goToMainMenu(); // go back to main menu
ollie140 0:4a66fd16c223 432 lcd.refresh();
ollie140 0:4a66fd16c223 433 }
ollie140 0:4a66fd16c223 434
ollie140 0:4a66fd16c223 435 void nightMenu()
ollie140 0:4a66fd16c223 436 {
ollie140 0:4a66fd16c223 437 lcd.clear();
ollie140 0:4a66fd16c223 438 lcd.printString("NIGHT MODE",12,0);
ollie140 0:4a66fd16c223 439 lcd.printString("DAY",33,3);
ollie140 0:4a66fd16c223 440 lcd.printString("NIGHT",27,5);
ollie140 0:4a66fd16c223 441
ollie140 0:4a66fd16c223 442 if (pot <= 0.5f) {
ollie140 0:4a66fd16c223 443 MenuLine3Short();
ollie140 0:4a66fd16c223 444 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 445 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 446
ollie140 0:4a66fd16c223 447 circle_position_NIGHT = 27; // set y position for circle
ollie140 0:4a66fd16c223 448 lcd.normalMode(); // set the sreen to normal mode
ollie140 0:4a66fd16c223 449 }
ollie140 0:4a66fd16c223 450
ollie140 0:4a66fd16c223 451 } else {
ollie140 0:4a66fd16c223 452 MenuLine5Short();
ollie140 0:4a66fd16c223 453 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 454 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 455
ollie140 0:4a66fd16c223 456 circle_position_NIGHT = 43; // set y position for circle
ollie140 0:4a66fd16c223 457 lcd.inverseMode(); // set the screen to inverse mode
ollie140 0:4a66fd16c223 458 }
ollie140 0:4a66fd16c223 459 }
ollie140 0:4a66fd16c223 460 lcd.drawCircle(4,circle_position_NIGHT,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 461 lcd.drawCircle(80,circle_position_NIGHT,2,1); // draw a circle next to the selected option for the respective y position
ollie140 0:4a66fd16c223 462 goToMainMenu(); // go back to main menu
ollie140 0:4a66fd16c223 463 lcd.refresh();
ollie140 0:4a66fd16c223 464 }
ollie140 0:4a66fd16c223 465
ollie140 0:4a66fd16c223 466 void goToMainMenu()
ollie140 0:4a66fd16c223 467 {
ollie140 0:4a66fd16c223 468 if (g_botButton_flag) { // if the bottom button is pressed
ollie140 0:4a66fd16c223 469 g_botButton_flag = 0; // sets the flag to 0
ollie140 0:4a66fd16c223 470
ollie140 0:4a66fd16c223 471 current_screen = menu_state; // the current screen will go to the main menu (state 0)
ollie140 0:4a66fd16c223 472 }
ollie140 0:4a66fd16c223 473 }
ollie140 0:4a66fd16c223 474
ollie140 0:4a66fd16c223 475 void goToSelectedOption()
ollie140 0:4a66fd16c223 476 {
ollie140 0:4a66fd16c223 477 if (g_topButton_flag) {
ollie140 0:4a66fd16c223 478 g_topButton_flag = 0;
ollie140 0:4a66fd16c223 479
ollie140 0:4a66fd16c223 480 current_screen = selected_option; // the current screen will go to the selected option
ollie140 0:4a66fd16c223 481
ollie140 0:4a66fd16c223 482 }
ollie140 0:4a66fd16c223 483 }
ollie140 0:4a66fd16c223 484
ollie140 0:4a66fd16c223 485 void MenuLine1()
ollie140 0:4a66fd16c223 486 {
ollie140 0:4a66fd16c223 487 for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the second bank and inverts them
ollie140 0:4a66fd16c223 488 for (int j = 8; j <= 14; j++) {
ollie140 0:4a66fd16c223 489 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 490
ollie140 0:4a66fd16c223 491 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 492
ollie140 0:4a66fd16c223 493 } else {
ollie140 0:4a66fd16c223 494
ollie140 0:4a66fd16c223 495 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 496 }
ollie140 0:4a66fd16c223 497 }
ollie140 0:4a66fd16c223 498 }
ollie140 0:4a66fd16c223 499 }
ollie140 0:4a66fd16c223 500
ollie140 0:4a66fd16c223 501 void MenuLine1Short()
ollie140 0:4a66fd16c223 502 {
ollie140 0:4a66fd16c223 503 for (int i = 15; i < 70; i++) { // scans most of the pixels in the second bank and inverts them
ollie140 0:4a66fd16c223 504 for (int j = 8; j <= 14; j++) {
ollie140 0:4a66fd16c223 505 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 506
ollie140 0:4a66fd16c223 507 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 508
ollie140 0:4a66fd16c223 509 } else {
ollie140 0:4a66fd16c223 510
ollie140 0:4a66fd16c223 511 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 512 }
ollie140 0:4a66fd16c223 513 }
ollie140 0:4a66fd16c223 514 }
ollie140 0:4a66fd16c223 515 }
ollie140 0:4a66fd16c223 516 void MenuLine2()
ollie140 0:4a66fd16c223 517 {
ollie140 0:4a66fd16c223 518 for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the third bank and inverts them
ollie140 0:4a66fd16c223 519 for (int j = 16; j <= 22; j++) {
ollie140 0:4a66fd16c223 520 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 521
ollie140 0:4a66fd16c223 522 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 523
ollie140 0:4a66fd16c223 524 } else {
ollie140 0:4a66fd16c223 525
ollie140 0:4a66fd16c223 526 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 527 }
ollie140 0:4a66fd16c223 528 }
ollie140 0:4a66fd16c223 529 }
ollie140 0:4a66fd16c223 530 }
ollie140 0:4a66fd16c223 531
ollie140 0:4a66fd16c223 532 void MenuLine2Short()
ollie140 0:4a66fd16c223 533 {
ollie140 0:4a66fd16c223 534 for (int i = 15; i < 70; i++) { // scans most of the pixels in the third bank and inverts them
ollie140 0:4a66fd16c223 535 for (int j = 16; j <= 22; j++) {
ollie140 0:4a66fd16c223 536 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 537
ollie140 0:4a66fd16c223 538 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 539
ollie140 0:4a66fd16c223 540 } else {
ollie140 0:4a66fd16c223 541
ollie140 0:4a66fd16c223 542 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 543 }
ollie140 0:4a66fd16c223 544 }
ollie140 0:4a66fd16c223 545 }
ollie140 0:4a66fd16c223 546 }
ollie140 0:4a66fd16c223 547
ollie140 0:4a66fd16c223 548 void MenuLine3()
ollie140 0:4a66fd16c223 549 {
ollie140 0:4a66fd16c223 550 for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the fourth bank and inverts them
ollie140 0:4a66fd16c223 551 for (int j = 24; j <= 30; j++) {
ollie140 0:4a66fd16c223 552 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 553
ollie140 0:4a66fd16c223 554 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 555
ollie140 0:4a66fd16c223 556 } else {
ollie140 0:4a66fd16c223 557
ollie140 0:4a66fd16c223 558 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 559 }
ollie140 0:4a66fd16c223 560 }
ollie140 0:4a66fd16c223 561 }
ollie140 0:4a66fd16c223 562 }
ollie140 0:4a66fd16c223 563
ollie140 0:4a66fd16c223 564 void MenuLine3Short()
ollie140 0:4a66fd16c223 565 {
ollie140 0:4a66fd16c223 566 for (int i = 15; i < 70; i++) { // scans most of the pixels in the fourth bank and inverts them
ollie140 0:4a66fd16c223 567 for (int j = 24; j <= 30; j++) {
ollie140 0:4a66fd16c223 568 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 569
ollie140 0:4a66fd16c223 570 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 571
ollie140 0:4a66fd16c223 572 } else {
ollie140 0:4a66fd16c223 573
ollie140 0:4a66fd16c223 574 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 575 }
ollie140 0:4a66fd16c223 576 }
ollie140 0:4a66fd16c223 577 }
ollie140 0:4a66fd16c223 578 }
ollie140 0:4a66fd16c223 579
ollie140 0:4a66fd16c223 580 void MenuLine4()
ollie140 0:4a66fd16c223 581 {
ollie140 0:4a66fd16c223 582 for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the fifth bank and inverts them
ollie140 0:4a66fd16c223 583 for (int j = 32; j <= 38; j++) {
ollie140 0:4a66fd16c223 584 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 585
ollie140 0:4a66fd16c223 586 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 587
ollie140 0:4a66fd16c223 588 } else {
ollie140 0:4a66fd16c223 589
ollie140 0:4a66fd16c223 590 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 591 }
ollie140 0:4a66fd16c223 592 }
ollie140 0:4a66fd16c223 593 }
ollie140 0:4a66fd16c223 594 }
ollie140 0:4a66fd16c223 595
ollie140 0:4a66fd16c223 596 void MenuLine4Short()
ollie140 0:4a66fd16c223 597 {
ollie140 0:4a66fd16c223 598 for (int i = 15; i < 70; i++) { // scans most of the pixels in the fifth bank and inverts them
ollie140 0:4a66fd16c223 599 for (int j = 32; j <= 38; j++) {
ollie140 0:4a66fd16c223 600 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 601
ollie140 0:4a66fd16c223 602 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 603
ollie140 0:4a66fd16c223 604 } else {
ollie140 0:4a66fd16c223 605
ollie140 0:4a66fd16c223 606 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 607 }
ollie140 0:4a66fd16c223 608 }
ollie140 0:4a66fd16c223 609 }
ollie140 0:4a66fd16c223 610 }
ollie140 0:4a66fd16c223 611
ollie140 0:4a66fd16c223 612 void MenuLine5()
ollie140 0:4a66fd16c223 613 {
ollie140 0:4a66fd16c223 614 for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the sixth bank and inverts them
ollie140 0:4a66fd16c223 615 for (int j = 40; j <= 46; j++) {
ollie140 0:4a66fd16c223 616 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 617
ollie140 0:4a66fd16c223 618 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 619
ollie140 0:4a66fd16c223 620 } else {
ollie140 0:4a66fd16c223 621
ollie140 0:4a66fd16c223 622 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 623 }
ollie140 0:4a66fd16c223 624 }
ollie140 0:4a66fd16c223 625 }
ollie140 0:4a66fd16c223 626 }
ollie140 0:4a66fd16c223 627
ollie140 0:4a66fd16c223 628 void MenuLine5Short()
ollie140 0:4a66fd16c223 629 {
ollie140 0:4a66fd16c223 630 for (int i = 15; i < 70; i++) { // scans most of the pixels in the sixth bank and inverts them
ollie140 0:4a66fd16c223 631 for (int j = 40; j <= 46; j++) {
ollie140 0:4a66fd16c223 632 if (lcd.getPixel(i,j)) {
ollie140 0:4a66fd16c223 633
ollie140 0:4a66fd16c223 634 lcd.clearPixel(i,j);
ollie140 0:4a66fd16c223 635
ollie140 0:4a66fd16c223 636 } else {
ollie140 0:4a66fd16c223 637
ollie140 0:4a66fd16c223 638 lcd.setPixel(i,j);
ollie140 0:4a66fd16c223 639 }
ollie140 0:4a66fd16c223 640 }
ollie140 0:4a66fd16c223 641 }
ollie140 0:4a66fd16c223 642 }
ollie140 0:4a66fd16c223 643
ollie140 0:4a66fd16c223 644 void init_serial()
ollie140 0:4a66fd16c223 645 {
ollie140 0:4a66fd16c223 646 // set to highest baud - ensure terminal software matches
ollie140 0:4a66fd16c223 647 pc.baud(115200);
ollie140 0:4a66fd16c223 648 }
ollie140 0:4a66fd16c223 649
ollie140 0:4a66fd16c223 650 void init_K64F()
ollie140 0:4a66fd16c223 651 {
ollie140 0:4a66fd16c223 652 // on-board LEDs are active-low, so set pin high to turn them off.
ollie140 0:4a66fd16c223 653 r_led = 1;
ollie140 0:4a66fd16c223 654 g_led = 1;
ollie140 0:4a66fd16c223 655 b_led = 1;
ollie140 0:4a66fd16c223 656
ollie140 0:4a66fd16c223 657 // since the on-board switches have external pull-ups, we should disable the internal pull-down
ollie140 0:4a66fd16c223 658 // resistors that are enabled by default using InterruptIn
ollie140 0:4a66fd16c223 659 sw2.mode(PullNone);
ollie140 0:4a66fd16c223 660 sw3.mode(PullNone);
ollie140 0:4a66fd16c223 661
ollie140 0:4a66fd16c223 662 topButton.mode(PullDown); // set the top button to pull-down mode
ollie140 0:4a66fd16c223 663 botButton.mode(PullDown); // set the bottom button to pull-down mode
ollie140 0:4a66fd16c223 664 topButton.rise(&topButton_isr); // recognise the press of the button as a rise up (from mbed pin to 3V3)
ollie140 0:4a66fd16c223 665 botButton.rise(&botButton_isr); // recognise the press of the button as a rise up (from mbed pin to 3V3)
ollie140 0:4a66fd16c223 666
ollie140 0:4a66fd16c223 667 }
ollie140 0:4a66fd16c223 668
ollie140 0:4a66fd16c223 669 // time-triggered interrupt used for the sensorTicker
ollie140 0:4a66fd16c223 670 void timer_isr()
ollie140 0:4a66fd16c223 671 {
ollie140 0:4a66fd16c223 672 g_timer_flag = 1; // set flag in ISR
ollie140 0:4a66fd16c223 673 }
ollie140 0:4a66fd16c223 674
ollie140 0:4a66fd16c223 675 //time triggered interrupt used for the buttonsDebounce ticker
ollie140 0:4a66fd16c223 676 void timer1_isr()
ollie140 0:4a66fd16c223 677 {
ollie140 0:4a66fd16c223 678 g_timer1_flag = 0; // set flag in ISR
ollie140 0:4a66fd16c223 679
ollie140 0:4a66fd16c223 680 buttonsDebounce.detach(); // detach the buttonsDebounce ticker
ollie140 0:4a66fd16c223 681 }
ollie140 0:4a66fd16c223 682
ollie140 0:4a66fd16c223 683 //time triggered interrupt used for the potTicker
ollie140 0:4a66fd16c223 684 void timer2_isr()
ollie140 0:4a66fd16c223 685 {
ollie140 0:4a66fd16c223 686 g_timer2_flag = 1; // set flag in ISR
ollie140 0:4a66fd16c223 687 }
ollie140 0:4a66fd16c223 688
ollie140 0:4a66fd16c223 689 //event triggered interrupt
ollie140 0:4a66fd16c223 690 void botButton_isr()
ollie140 0:4a66fd16c223 691 {
ollie140 0:4a66fd16c223 692 if (!g_timer1_flag) { // when the button is pressed if the buttonsDebounce flag is on 0
ollie140 0:4a66fd16c223 693
ollie140 0:4a66fd16c223 694 g_botButton_flag = 1; // set the flag to 1
ollie140 0:4a66fd16c223 695
ollie140 0:4a66fd16c223 696 g_timer1_flag = 1; // set the flag to 1
ollie140 0:4a66fd16c223 697
ollie140 0:4a66fd16c223 698 buttonsDebounce.attach(&timer1_isr,0.2); // attach a short delay of 0.2 that will prevent the button from providing multiple inputs to the MCU
ollie140 0:4a66fd16c223 699
ollie140 0:4a66fd16c223 700 }
ollie140 0:4a66fd16c223 701
ollie140 0:4a66fd16c223 702 }
ollie140 0:4a66fd16c223 703
ollie140 0:4a66fd16c223 704 //event triggered interrupt
ollie140 0:4a66fd16c223 705 void topButton_isr()
ollie140 0:4a66fd16c223 706 {
ollie140 0:4a66fd16c223 707 if (!g_timer1_flag) { // when the button is pressed if the buttonsDebounce flag is on 0
ollie140 0:4a66fd16c223 708
ollie140 0:4a66fd16c223 709 g_topButton_flag = 1; // set the flag to 1
ollie140 0:4a66fd16c223 710
ollie140 0:4a66fd16c223 711 g_timer1_flag = 1; // set the flag to 1
ollie140 0:4a66fd16c223 712
ollie140 0:4a66fd16c223 713 buttonsDebounce.attach(&timer1_isr,0.2); // attach a short delay of 0.2 that will prevent the button from providing multiple inputs to the MCU
ollie140 0:4a66fd16c223 714
ollie140 0:4a66fd16c223 715 }
ollie140 0:4a66fd16c223 716
ollie140 0:4a66fd16c223 717 }