ELEC2645 (2015/16) / Mbed 2 deprecated Year2SensorProject

Dependencies:   N5110 SRF02 TMP102 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /**
00002 @file main.cpp
00003 @brief program implementation
00004 
00005 */
00006 #include "main.h"
00007 
00008 int main()
00009 {
00010     introScreen();
00011     while (1) {
00012         if (g_timer2_flag) {
00013             g_timer2_flag = 0;
00014             if (current_screen == menu_state) { //Main menu
00015                 mainMenu();
00016             } else if (current_screen == modes_state) { //modes menu
00017                 modesMenu();
00018             } else if (current_screen == peripherals_state) { // peripherals menu
00019                 peripheralsMenu();
00020             } else if (current_screen == brightness_state) { // brightness menu
00021                 brightnessMenu();
00022             } else if (current_screen == sound_state) { // sound menu
00023                 soundMenu();
00024             } else if (current_screen == ledMenu_state) { // LED menu
00025                 LEDMenu();
00026             } else if (current_screen == nightMenu_state) { // night menu
00027                 nightMenu();
00028             } else if (current_screen == parkingMode_state) { // parking mode setup
00029                 printBars();
00030             } else if (current_screen == numericMode_state) { // numeric mode setup
00031                 numericMode();
00032             }
00033         }
00034         sleep();
00035     }
00036 }
00037 
00038 
00039 float getDistance()
00040 {
00041 
00042     emptyVariable = 0; // initialise the empty variable
00043 
00044     for (int i = 0 ; i<10; i++) { // intitialises the measurement for loop
00045 
00046         realDistance = srf.getDistanceCm(); // get a distance measurement for every i value
00047         emptyVariable = emptyVariable + realDistance ; // add all these measurements up
00048     }
00049 
00050     distance = emptyVariable/10.0; // divide all the measurements by 10 to take the average
00051     return distance; // return the distance
00052 
00053 }
00054 
00055 void drawCar()
00056 {
00057     lcd.drawRect(1,8,56,32,1);  // main car rectangle
00058     lcd.drawRect(15,6,9,1,1);   // right front wheel
00059     lcd.drawRect(40,6,9,1,1);   // right back wheel
00060     lcd.drawRect(15,41,9,1,1);  // left front wheel
00061     lcd.drawRect(40,41,9,1,1);  // left back wheel
00062     lcd.drawRect(20,14,9,20,2); // front window
00063     lcd.drawRect(42,16,6,16,2);  // back window
00064 
00065 }
00066 
00067 void reallyCloseDistance()
00068 {
00069     lcd.drawRect(60,8,3,32,1);  // really close bar
00070     lcd.drawRect(66,8,3,32,1);  // close bar
00071     lcd.drawRect(72,8,3,32,1);  // medium bar
00072     lcd.drawRect(78,8,3,32,1);  // far bar
00073 }
00074 
00075 void closeDistance()
00076 {
00077     lcd.drawRect(66,8,3,32,1);  // close bar
00078     lcd.drawRect(72,8,3,32,1);  // medium bar
00079     lcd.drawRect(78,8,3,32,1);  // far bar
00080 }
00081 
00082 void mediumDistance()
00083 {
00084     lcd.drawRect(72,8,3,32,1);  // medium bar
00085     lcd.drawRect(78,8,3,32,1);  // far bar
00086 }
00087 
00088 void farDistance()
00089 {
00090     lcd.drawRect(78,8,3,32,1);  // far bar
00091 }
00092 
00093 void printBars()
00094 {
00095     potTicker.detach(); // detach the potentiometer ticker 
00096 
00097     sensorTicker.attach(&timer_isr,0.7); // attach a ticker that will be called every 0.7 seconds
00098 
00099     while (current_screen == parkingMode_state) { // while the parking mode menu is true 
00100 
00101         dist = getDistance(); // get the distance in cm
00102 
00103         T = tmp102.get_temperature(); // get the temperature in C
00104 
00105         temp = floor(T); // floor the temperature to get an integer value
00106 
00107         LED = 0; // Set the LED to off
00108 
00109         if (g_timer_flag) { // if the timer event is called
00110 
00111             g_timer_flag = 0; // reset flag back to 0
00112 
00113             lcd.clear();// clear the screen
00114 
00115             length2 = sprintf(buffer2,"%dC",temp); // assign a value to the string lenght
00116 
00117             if (length2 <= 14) { // if string will fit on display
00118                 lcd.printString(buffer2,66,0); // print the desired string
00119             }
00120 
00121             if (dist > 140) { // if distance is more than 140 cm
00122                 drawCar(); // draw the car shape
00123                 buzzerOFF();
00124             } else if (dist <= 140 && dist > 100) { // if distance is between 140 cm and 100 cm
00125                 drawCar(); // draw the car shape
00126                 farDistance(); // draw 1 bar
00127                 buzzerOFF();
00128             } else if (dist <= 100 && dist > 70) { // if distance is between 100 cm and 70 cm
00129                 drawCar(); // draw the car shape
00130                 mediumDistance(); // draw 2 bars
00131                 buzzerOFF();
00132             } else if (dist <= 70 && dist > 40) { // if distance is between 70 cm and 40 cm
00133                 drawCar(); // draw the car shape
00134                 closeDistance(); // draw 3 bars
00135                 buzzerOFF();
00136             } else { // if distance is less than 40 cm
00137                 drawCar(); // draw the car shape
00138                 reallyCloseDistance(); // draw 4 bars
00139                 
00140                 if (buzzer_state == buzzerON_state) {
00141                     buzzerON();
00142                 } else {
00143                     buzzerOFF();
00144                 }
00145                 
00146                 if (led_state == LEDON_state) { // if the state of the LED menu is on 
00147                     LED = 1; // turn on the LED
00148                 } else {
00149                     LED = 0; // keep the LED off
00150                 }
00151             }
00152 
00153             if (g_botButton_flag) { // if the button is pressed
00154                 g_botButton_flag = 0; // reset the flag
00155 
00156                 LED = 0; // turn off the LED
00157                 
00158                 buzzerOFF(); // sets the duty cycle to 0
00159                 
00160                 sensorTicker.detach(); // detach the sensor ticker to save computing powr and battery
00161 
00162                 current_screen = menu_state; // go back to the main menu
00163 
00164                 potTicker.attach(&timer2_isr,0.2); // attach the potentiometer ticker
00165 
00166             }
00167             lcd.refresh(); // refresh the screen
00168         }
00169         sleep(); // send the MCU back to sleep to save power
00170     }
00171 
00172 }
00173 
00174 void numericMode()
00175 {
00176     potTicker.detach(); // detanch the ticker potentiometer
00177 
00178     sensorTicker.attach(&timer_isr,0.7); // attach the sensor ticker to be called every 0.7 seconds
00179 
00180     while (current_screen == numericMode_state) {
00181 
00182         dist = getDistance(); // get the distance in cm
00183 
00184         T = tmp102.get_temperature(); // get the temperature in C
00185 
00186         if (g_timer_flag) { // if time event is triggered
00187 
00188             lcd.clear(); // clear the LCD
00189 
00190             length1 = sprintf(buffer,"D = %.2f cm",dist); // assign a lenght integer for the distance string
00191 
00192             length2 = sprintf(buffer2,"T = %.2f C",T); // assign a lenght integer for the temperature string
00193 
00194             if (length1 <= 14) { // if string will fit on display
00195                 lcd.printString(buffer,0,2);
00196             }
00197             if (length2 <= 14) { // if string will fit on display
00198                 lcd.printString(buffer2,0,4);
00199             }
00200 
00201             if (g_botButton_flag) { // if the event trigger is activated by pressing the bottom button
00202                 g_botButton_flag = 0; // reset the flag 
00203                 
00204                 sensorTicker.detach(); // detach the sensor ticker
00205 
00206                 current_screen = menu_state; // go back to the main menu
00207 
00208                 potTicker.attach(&timer2_isr,0.2); // attach the potentiometer ticker
00209 
00210             }
00211 
00212             lcd.refresh(); // refresh the LCD
00213         }
00214         sleep(); // save power by sending the MCU to sleep
00215     }
00216 }
00217 
00218 
00219 void introScreen()
00220 {
00221 
00222     init_K64F(); // intialise all of the K64F's on board peripherals
00223     init_serial();
00224     potTicker.attach(&timer2_isr,0.2); // attach a ticker for the potentiometer
00225     tmp102.init(); // initialise the temperature sensor
00226     lcd.init(); // initialise the LCD display
00227     lcd.setBrightness(1.0);
00228     lcd.printString("PARKING",21,0); 
00229     lcd.printString("SENSOR",25,2);
00230     lcd.printString("BY",36,3);
00231     lcd.printString("ARNAU SEGURA",6,4); 
00232     led_state = LEDON_state; // start with the warning LED on the ON state
00233     buzzer.period(1/1000.0);
00234     buzzer_state = buzzerON_state;
00235     wait(3); // wait 3 seconds
00236     lcd.clear(); // clear the LCD
00237     lcd.refresh(); // refresh the LCD
00238 
00239 }
00240 
00241 void mainMenu()
00242 {
00243 
00244     lcd.clear(); // clear the LCD
00245     lcd.printString("MENU",28,0); 
00246     lcd.printString("MODES",25,2); 
00247     lcd.printString("PERIPHERALS",9,4);
00248     
00249     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
00250 
00251     if (pot < 0.5f) { // if the potentiometer is normalised to less than 0.5
00252         MenuLine2(); // invert pixels in bank 3
00253         selected_option = modes_state;
00254     } else {
00255         MenuLine4(); // invert pixels in bank 5
00256         selected_option = peripherals_state;
00257     }
00258     goToSelectedOption(); // if the top button is pressed go to the selected option
00259     lcd.refresh();
00260 }
00261 
00262 void peripheralsMenu()
00263 {
00264     lcd.clear();
00265     lcd.printString("PERIPHERALS",9,0);
00266     lcd.printString("BRIGHTNESS",12,2);
00267     lcd.printString("SOUND",25,3);
00268     lcd.printString("LEDs",28,4);
00269     lcd.printString("NIGHT LCD",15,5);
00270     if (pot <= 0.25f) {
00271         MenuLine2(); // invert pixels in bank 3
00272         selected_option = brightness_state;
00273     } else if (pot <= 0.5f) {
00274         MenuLine3(); // invert pixels in bank 4
00275         selected_option = sound_state;
00276     } else if (pot <= 0.75f) {
00277         MenuLine4(); // invert pixels in bank 5
00278         selected_option = ledMenu_state;
00279     } else {
00280         MenuLine5(); // invert pixels in bank 6
00281         selected_option = nightMenu_state;
00282     }
00283     goToMainMenu(); // if bottom button is pressed go back to main menu
00284     goToSelectedOption(); // if the top button is pressed go to the selected option
00285     lcd.refresh();
00286 }
00287 
00288 void modesMenu()
00289 {
00290     lcd.clear();
00291     lcd.printString("MODES",25,0);
00292     lcd.printString("PARKING MODE",6,2);
00293     lcd.printString("NUMERIC MODE",6,4);
00294 
00295     if (pot <= 0.5f) {
00296         MenuLine2(); // invert pixels in bank 3
00297         selected_option = parkingMode_state;
00298     } else {
00299         MenuLine4(); // invert pixels in bank 5
00300         selected_option = numericMode_state;
00301     }
00302     goToMainMenu(); // go back to main menu
00303     goToSelectedOption(); // go to selected option
00304     lcd.refresh();
00305 }
00306 
00307 void soundMenu()
00308 {
00309     lcd.clear();
00310     lcd.printString("SOUND MENU",12,0);
00311     lcd.printString("SOUND ON",18,3);
00312     lcd.printString("SOUND OFF",15,5);
00313 
00314     if (pot <= 0.5f) {
00315         MenuLine3Short(); // partially inverts bank 4 of the LCD
00316         if (g_topButton_flag) {
00317             g_topButton_flag = 0;
00318             
00319             buzzer_state = buzzerON_state;
00320             circle_position_SOUND = 27; // set y position for the circle to be drawed
00321         }
00322     } else {
00323         MenuLine5Short(); // partially inverts bank 6 of the LCD
00324         if (g_topButton_flag) {
00325             g_topButton_flag = 0;
00326             
00327             buzzer_state = buzzerOFF_state;
00328             circle_position_SOUND = 43; // set y position for the circle to be drawed
00329         }
00330     }
00331     
00332     lcd.drawCircle(4,circle_position_SOUND,2,1); // draw a circle next to the selected option for the respective y position
00333     lcd.drawCircle(80,circle_position_SOUND,2,1); // draw a circle next to the selected option for the respective y position
00334     goToMainMenu(); // go back to main menu
00335     lcd.refresh();
00336 }
00337 
00338 void buzzerON()
00339 {
00340     buzzer.write(0.5); // set the buzzers duty cycle to 50%
00341 }
00342 
00343 void buzzerOFF()
00344 {
00345     buzzer.write(0.0); // set the buzzers duty cycle to 0%
00346 }
00347 
00348 void LEDMenu()
00349 {
00350 
00351     lcd.clear();
00352     lcd.printString("LED MENU",18,0);
00353     lcd.printString("LED ON",24,3);
00354     lcd.printString("LED OFF",21,5);
00355 
00356     if (pot <= 0.5f) {
00357         MenuLine3Short(); // partially inverts bank 4 of the LCD
00358         if (g_topButton_flag) {
00359             g_topButton_flag = 0;
00360 
00361             circle_position_LED = 27; // set y position for the circle to be drawn
00362             led_state = LEDON_state; // set the empty led state variable to the LED On state
00363         }
00364 
00365     } else {
00366         MenuLine5Short(); // partially inverts bank 6 of the LCD
00367         if (g_topButton_flag) {
00368             g_topButton_flag = 0;
00369 
00370             circle_position_LED = 43; // set y position for the circle to be drawn
00371             led_state = LEDOFF_state; // set the empty led state variable to the LED Off state
00372         }
00373     }
00374     
00375     lcd.drawCircle(4,circle_position_LED,2,1); // draw a circle next to the selected option for the respective y position
00376     lcd.drawCircle(80,circle_position_LED,2,1); // draw a circle next to the selected option for the respective y position
00377     goToMainMenu(); // go to main menu
00378     lcd.refresh();
00379 
00380 }
00381 
00382 void brightnessMenu()
00383 {
00384     lcd.clear();
00385     lcd.printString("BRIGHTNESS",12,0);
00386     lcd.printString("0%",36,1);
00387     lcd.printString("25%",33,2);
00388     lcd.printString("50%",33,3);
00389     lcd.printString("75%",33,4);
00390     lcd.printString("100%",30,5);
00391 
00392     if (pot <= 0.2f) {
00393         MenuLine1Short(); // partially inverts bank 2 of the LCD
00394         if (g_topButton_flag) {
00395             g_topButton_flag = 0;
00396             circle_position_brightness = 11; // set y position for circle
00397             screenLED.write(0.0); // set the brighness to 0%
00398         }
00399     } else if (pot <= 0.4f) {
00400         MenuLine2Short(); // partially inverts bank 3 of the LCD
00401         if (g_topButton_flag) {
00402             g_topButton_flag = 0;
00403             circle_position_brightness = 19; // set y position for circle
00404             screenLED.write(0.25); // set the brighness to 25%
00405         }
00406     } else if (pot <= 0.6f) {
00407         MenuLine3Short(); // partially inverts bank 4 of the LCD
00408         if (g_topButton_flag) {
00409             g_topButton_flag = 0;
00410             circle_position_brightness = 27; // set y position for circle
00411             screenLED.write(0.5); // set the brighness to 50%
00412         }
00413     } else if (pot <= 0.8f) {
00414         MenuLine4Short(); // partially inverts bank 5 of the LCD
00415         if (g_topButton_flag) {
00416             g_topButton_flag = 0;
00417             circle_position_brightness = 35; // set y position for circle
00418             screenLED.write(0.75); // set the brighness to 75%
00419         }
00420     } else {
00421         MenuLine5Short(); // partially inverts bank 6 of the LCD
00422         if (g_topButton_flag) {
00423             g_topButton_flag = 0;
00424             circle_position_brightness = 43; // set y position for circle
00425             screenLED.write(1.0); // set the brighness to 100%
00426         }
00427     }
00428     
00429     lcd.drawCircle(4,circle_position_brightness,2,1); // draw a circle next to the selected option for the respective y position
00430     lcd.drawCircle(80,circle_position_brightness,2,1); // draw a circle next to the selected option for the respective y position
00431     goToMainMenu(); // go back to main menu
00432     lcd.refresh();
00433 }
00434 
00435 void nightMenu()
00436 {
00437     lcd.clear();
00438     lcd.printString("NIGHT MODE",12,0);
00439     lcd.printString("DAY",33,3);
00440     lcd.printString("NIGHT",27,5);
00441     
00442     if (pot <= 0.5f) {
00443         MenuLine3Short();
00444         if (g_topButton_flag) {
00445             g_topButton_flag = 0;
00446 
00447             circle_position_NIGHT = 27; // set y position for circle
00448             lcd.normalMode(); // set the sreen to normal mode
00449         }
00450 
00451     } else {
00452         MenuLine5Short();
00453         if (g_topButton_flag) {
00454             g_topButton_flag = 0;
00455 
00456             circle_position_NIGHT = 43; // set y position for circle
00457             lcd.inverseMode(); // set the screen to inverse mode
00458         }
00459     }
00460     lcd.drawCircle(4,circle_position_NIGHT,2,1); // draw a circle next to the selected option for the respective y position
00461     lcd.drawCircle(80,circle_position_NIGHT,2,1); // draw a circle next to the selected option for the respective y position
00462     goToMainMenu(); // go back to main menu
00463     lcd.refresh();
00464 }
00465 
00466 void goToMainMenu()
00467 {
00468     if (g_botButton_flag) { // if the bottom button is pressed
00469         g_botButton_flag = 0; // sets the flag to 0
00470 
00471         current_screen = menu_state; // the current screen will go to the main menu (state 0)
00472     }
00473 }
00474 
00475 void goToSelectedOption()
00476 {
00477     if (g_topButton_flag) {
00478         g_topButton_flag = 0;
00479 
00480         current_screen = selected_option; // the current screen will go to the selected option
00481 
00482     }
00483 }
00484 
00485 void MenuLine1()
00486 {
00487     for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the second bank and inverts them
00488         for (int j = 8; j <= 14; j++) {
00489             if (lcd.getPixel(i,j)) {
00490 
00491                 lcd.clearPixel(i,j);
00492 
00493             } else {
00494 
00495                 lcd.setPixel(i,j);
00496             }
00497         }
00498     }
00499 }
00500 
00501 void MenuLine1Short()
00502 {
00503     for (int i = 15; i < 70; i++) { // scans most of the pixels in the second bank and inverts them
00504         for (int j = 8; j <= 14; j++) {
00505             if (lcd.getPixel(i,j)) {
00506 
00507                 lcd.clearPixel(i,j);
00508 
00509             } else {
00510 
00511                 lcd.setPixel(i,j);
00512             }
00513         }
00514     }
00515 }
00516 void MenuLine2()
00517 {
00518     for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the third bank and inverts them
00519         for (int j = 16; j <= 22; j++) {
00520             if (lcd.getPixel(i,j)) {
00521 
00522                 lcd.clearPixel(i,j);
00523 
00524             } else {
00525 
00526                 lcd.setPixel(i,j);
00527             }
00528         }
00529     }
00530 }
00531 
00532 void MenuLine2Short()
00533 {
00534     for (int i = 15; i < 70; i++) { // scans most of the pixels in the third bank and inverts them
00535         for (int j = 16; j <= 22; j++) {
00536             if (lcd.getPixel(i,j)) {
00537 
00538                 lcd.clearPixel(i,j);
00539 
00540             } else {
00541 
00542                 lcd.setPixel(i,j);
00543             }
00544         }
00545     }
00546 }
00547 
00548 void MenuLine3()
00549 {
00550     for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the fourth bank and inverts them
00551         for (int j = 24; j <= 30; j++) {
00552             if (lcd.getPixel(i,j)) {
00553 
00554                 lcd.clearPixel(i,j);
00555 
00556             } else {
00557 
00558                 lcd.setPixel(i,j);
00559             }
00560         }
00561     }
00562 }
00563 
00564 void MenuLine3Short()
00565 {
00566     for (int i = 15; i < 70; i++) { // scans most of the pixels in the fourth bank and inverts them
00567         for (int j = 24; j <= 30; j++) {
00568             if (lcd.getPixel(i,j)) {
00569 
00570                 lcd.clearPixel(i,j);
00571 
00572             } else {
00573 
00574                 lcd.setPixel(i,j);
00575             }
00576         }
00577     }
00578 }
00579 
00580 void MenuLine4()
00581 {
00582     for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the fifth bank and inverts them
00583         for (int j = 32; j <= 38; j++) {
00584             if (lcd.getPixel(i,j)) {
00585 
00586                 lcd.clearPixel(i,j);
00587 
00588             } else {
00589 
00590                 lcd.setPixel(i,j);
00591             }
00592         }
00593     }
00594 }
00595 
00596 void MenuLine4Short()
00597 {
00598     for (int i = 15; i < 70; i++) { // scans most of the pixels in the fifth bank and inverts them
00599         for (int j = 32; j <= 38; j++) {
00600             if (lcd.getPixel(i,j)) {
00601 
00602                 lcd.clearPixel(i,j);
00603 
00604             } else {
00605 
00606                 lcd.setPixel(i,j);
00607             }
00608         }
00609     }
00610 }
00611 
00612 void MenuLine5()
00613 {
00614     for (int i = 0; i < WIDTH; i++) { //scans all the pixels in the sixth bank and inverts them
00615         for (int j = 40; j <= 46; j++) {
00616             if (lcd.getPixel(i,j)) {
00617 
00618                 lcd.clearPixel(i,j);
00619 
00620             } else {
00621 
00622                 lcd.setPixel(i,j);
00623             }
00624         }
00625     }
00626 }
00627 
00628 void MenuLine5Short()
00629 {
00630     for (int i = 15; i < 70; i++) { // scans most of the pixels in the sixth bank and inverts them
00631         for (int j = 40; j <= 46; j++) {
00632             if (lcd.getPixel(i,j)) {
00633 
00634                 lcd.clearPixel(i,j);
00635 
00636             } else {
00637 
00638                 lcd.setPixel(i,j);
00639             }
00640         }
00641     }
00642 }
00643 
00644 void init_serial()
00645 {
00646     // set to highest baud - ensure terminal software matches
00647     pc.baud(115200);
00648 }
00649 
00650 void init_K64F()
00651 {
00652     // on-board LEDs are active-low, so set pin high to turn them off.
00653     r_led = 1;
00654     g_led = 1;
00655     b_led = 1;
00656 
00657     // since the on-board switches have external pull-ups, we should disable the internal pull-down
00658     // resistors that are enabled by default using InterruptIn
00659     sw2.mode(PullNone);
00660     sw3.mode(PullNone);
00661 
00662     topButton.mode(PullDown); // set the top button to pull-down mode
00663     botButton.mode(PullDown); // set the bottom button to pull-down mode
00664     topButton.rise(&topButton_isr); // recognise the press of the button as a rise up (from mbed pin to 3V3)
00665     botButton.rise(&botButton_isr); // recognise the press of the button as a rise up (from mbed pin to 3V3)
00666 
00667 }
00668 
00669 // time-triggered interrupt used for the sensorTicker
00670 void timer_isr()
00671 {
00672     g_timer_flag = 1;   // set flag in ISR
00673 }
00674 
00675 //time triggered interrupt used for the buttonsDebounce ticker
00676 void timer1_isr()
00677 {
00678     g_timer1_flag = 0;   // set flag in ISR
00679 
00680     buttonsDebounce.detach(); // detach the buttonsDebounce ticker
00681 }
00682 
00683 //time triggered interrupt used for the potTicker 
00684 void timer2_isr()
00685 {
00686     g_timer2_flag = 1;   // set flag in ISR
00687 }
00688 
00689 //event triggered interrupt
00690 void botButton_isr()
00691 {
00692     if (!g_timer1_flag) { // when the button is pressed if the buttonsDebounce flag is on 0
00693 
00694         g_botButton_flag = 1; // set the flag to 1
00695 
00696         g_timer1_flag = 1; // set the flag to 1
00697 
00698         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
00699 
00700     }
00701 
00702 }
00703 
00704 //event triggered interrupt
00705 void topButton_isr()
00706 {
00707     if (!g_timer1_flag) { // when the button is pressed if the buttonsDebounce flag is on 0
00708 
00709         g_topButton_flag = 1; // set the flag to 1
00710 
00711         g_timer1_flag = 1; // set the flag to 1
00712 
00713         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
00714 
00715     }
00716 
00717 }