Andreas Konstantinou / Mbed 2 deprecated ParkingSensor

Dependencies:   N5110 PowerControl SRF02 beep 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 Reverse Parking Sensor Project
00004 */
00005 
00006 #include "main.h"
00007 
00008 void Get_Average() 
00009 {  
00010   distance  =0;//set the distance to 0
00011   int counter =0; //set the counter to 0 
00012   
00013   //for loop to store 5 sensor's values
00014    for ( counter =0; counter<5; counter++) {
00015             
00016              Distance_Array  [counter] =srf02.getDistanceCm(); //store the value of the sensor in the array 
00017      } 
00018     
00019     distance = (Distance_Array [0] + Distance_Array [1]+Distance_Array [2] + Distance_Array [3]+Distance_Array [4])/5; // get the average of the five values of the sensor  
00020 }
00021     
00022 //set power down the USB interface
00023 int semihost_powerdown()
00024 {
00025     uint32_t arg;
00026     return __semihost(USR_POWERDOWN, &arg);
00027     
00028     }
00029     
00030 //Interrupt Service Routine
00031 void button1_Pressed()
00032 {
00033     button1_flag  = !button1_flag ; //set flag
00034 }
00035 void button2_Pressed()
00036 {
00037     button2_flag  = !button2_flag ; //set flag
00038 }
00039 void button3_Pressed()
00040 {
00041     button3_flag  = !button3_flag ; //set flag
00042 }
00043 void button4_Pressed()
00044 {
00045     button4_flag  = !button4_flag ; //set flag
00046 }
00047 
00048 void Print_Time_Date()
00049 {
00050     char buffer_time_lcd[14];// buffer to store the time into the 14 characters each char has 6 pixels,so 84/6 = 14
00051     char buffer_date_lcd[14];
00052     time_t seconds = time(NULL); // get current time
00053 
00054     // format time and date into 2 strings (time and date)
00055     strftime(buffer_time_lcd, 14 , "%r",localtime(&seconds));
00056     strftime(buffer_date_lcd, 14 , "%d %b %G ",localtime(&seconds));
00057 
00058     // print current date and time value on the LCD
00059     lcd.printString(buffer_time_lcd,0,4);
00060     lcd.printString(buffer_date_lcd,0,5);
00061 }
00062 
00063 // Interrupt Service Routine
00064 void timerExpired_red()
00065 {
00066     timerflag_red  = 1; // set flag
00067 }
00068 
00069 void timerExpired_yellow()
00070 {
00071     timerflag_yellow = 1; // set flag
00072 }
00073 
00074 void timerExpired_green()
00075 {
00076     timerflag_green  = 1; // set flag
00077 }
00078 
00079 void buttonOperation_1()
00080 {
00081     // if button1 is pressed
00082     if (button1_flag ) {
00083         a2 =ain2.read(); // read value of potentiometer
00084         if (distance  <= 16) {
00085             //set the values of leds
00086             led_yellow =0;
00087             led_green =0;
00088             led_red =  1;
00089             buzzer.beep(500+a2 *1000,2.0);// buzzer makes sound with a delay of 2 seconds
00090         }
00091         if (distance  > 16 && distance  < 100) {
00092             if (timerflag_red ) { // if flag is set
00093                 timerflag_red  = 0; // reset flag
00094                 led_yellow =0;
00095                 led_green =0;
00096                 led_red = ! led_red;
00097                 buzzer.beep(500+a2 *1000,0.2);// buzzer makes sound with a delay of 2 seconds
00098             }
00099         }
00100         if(distance  >= 100 && distance  < 300) {
00101             if (timerflag_yellow ) { // if flag is set
00102                 timerflag_yellow  = 0; // reset flag
00103                 led_red =0;
00104                 led_green =0;
00105                 led_yellow = ! led_yellow;
00106                 buzzer.beep(500+a2 *1000,0.5); // buzzer makes sound with a delay of 0.5 seconds
00107             }
00108         }
00109 
00110         if (distance  >= 300 && distance  <=600 ) {
00111             if (timerflag_green ) { // if flag is set
00112                 timerflag_green  = 0; // reset flag
00113                 led_red =0;
00114                 led_yellow =0;
00115                 led_green = ! led_green;
00116                 buzzer.beep(500+a2 *1000,0.8); // buzzer makes sound with a delay of 0.5 seconds
00117             }
00118         }
00119 
00120         if (distance  >600 ) {
00121             led_red =0;
00122             led_yellow =0;
00123             led_green =0;
00124         }
00125     }
00126 
00127     else  {
00128         if (distance  < 100) {
00129             led_yellow =0;
00130             led_green =0;
00131             led_red = 1;
00132         } else
00133             led_red =0;
00134 
00135 
00136         if (distance  >= 100 && distance  < 300) {
00137             led_red =0;
00138             led_green =0;
00139             led_yellow = 1;
00140         } else
00141             led_yellow =0;
00142 
00143         if (distance  >= 300 && distance  <=600 ) {
00144             led_red =0;
00145             led_yellow =0;
00146             led_green = 1;
00147         } else
00148             led_green =0;
00149 
00150         if (distance  >600 ) {
00151             led_red =0;
00152             led_yellow =0;
00153             led_green =0;
00154         }
00155     }
00156 }
00157 
00158 void buttonOperation_2()
00159 {
00160     
00161     if (button2_flag ==0 && button3_flag ==0 && button4_flag ==0) {
00162 
00163         int length = sprintf(buffer ,"%.fcm",distance ); // print formatted data to buffer
00164         // it is important the format specifier ensures the length will fit in the buffer
00165         if (length == 5 ) { // if string will fit on display
00166 
00167             lcd.clear(); // clear LCD
00168             lcd.refresh(); // refresh LCD
00169             lcd.printString(buffer ,25,2);// display on screen
00170         }
00171 
00172         if (length < 5 ) { // if string will fit on display
00173             lcd.clear();
00174             lcd.refresh();
00175             lcd.printString(buffer ,29,2);// display on screen
00176         }
00177     }
00178 
00179     if (button2_flag ==1 && button3_flag ==0 && button4_flag ==0) {
00180 
00181         int length = sprintf(buffer ,"%.2fm",distance /100);
00182         if (length <= 5) { // if string will fit on display
00183             lcd.clear();
00184             lcd.refresh();
00185             lcd.printString(buffer ,26,2);// display on screen
00186         }
00187 
00188     }
00189 
00190     if (distance  < 16) {
00191         lcd.clear();
00192         lcd.refresh();
00193         lcd.printString("STOP",28,2);
00194         lcd.printString("YOU WILL CRASH",0,0);
00195 
00196     }
00197 
00198     if (distance < 100 && distance >=16) {
00199 
00200         lcd.printString("***DANGER***",5,0);//display on the N5110 LCD
00201     }
00202 
00203     else if (distance  >=  100 && distance  <300) {
00204 
00205         lcd.printString("Be Careful",12,0);
00206 
00207     } else if (distance  >=  300 && distance  <=600) {
00208 
00209         lcd.printString("***Move***",11,0);
00210     }
00211 
00212     else if (distance  >  600) {
00213 
00214         lcd.clear();
00215         lcd.refresh();
00216         lcd.printString("*Out of range*",0,0);
00217         lcd.printString("MOVE",28,2);
00218     }
00219 
00220     //draw rectacular and lines on the screen
00221     lcd.drawRect(20,10,40,18,0);
00222     lcd.drawRect(21,11,38,16,0);
00223     lcd.drawRect(22,12,36,14,0);
00224     lcd.drawLine(0,19,20,19,1);
00225     lcd.drawLine(60,19,83,19,1);
00226     //call the function
00227     Print_Time_Date();
00228 
00229 }
00230 void buttonOperation_3()
00231 {
00232 
00233     int length = sprintf(buffer ,"%.2fm",distance /100); // print formatted data to buffer
00234     // it is important the format specifier ensures the length will fit in the buffer
00235     if (length <= 5 && distance>=16 && distance <=600) { // if string will fit on display
00236         lcd.printString(buffer ,28,3);
00237     }
00238 
00239     int counter_Y = 40;//initial variable for the y-axes of the screen
00240     int counter_X_L = 0; // initial variable for the x-axes on the left side of the screen
00241     int counter_X_R = 83;// initial variable for the x-axes on the right side of the screen
00242 
00243     if (distance  < 16) {
00244         lcd.printString("STOP",30,3);
00245         lcd.printString("YOU WILL CRASH",0,0);
00246 
00247         while (counter_Y>=15) {
00248             // for loop to set the pixels
00249             for (int i = counter_Y; i<41; i++) {
00250                 lcd.setPixel(counter_X_L,i);
00251                 lcd.setPixel(counter_X_R,i);
00252             }
00253             counter_Y = counter_Y -1;
00254             counter_X_L = counter_X_L +1;
00255             counter_X_R = counter_X_R -1;
00256         }
00257     }
00258 
00259     if (distance  >= 16 && distance  <= 40) {
00260         lcd.printString("***DANGER***",5,0);//display on the N5110 LCD
00261 
00262         while (counter_Y>=17) {
00263 
00264             for (int i = counter_Y; i<41; i++) {
00265                 lcd.setPixel(counter_X_L,i);
00266                 lcd.setPixel(counter_X_R,i);
00267             }
00268 
00269             counter_Y = counter_Y -1;
00270             counter_X_L = counter_X_L +1;
00271             counter_X_R = counter_X_R -1;
00272         }
00273     }
00274     if (distance  > 40 && distance  <= 100) {
00275         lcd.printString("***DANGER***",5,0);
00276 
00277         while (counter_Y>=19) {
00278 
00279             for (int i = counter_Y; i<41; i++) {
00280                 lcd.setPixel(counter_X_L,i);
00281                 lcd.setPixel(counter_X_R,i);
00282             }
00283 
00284             counter_Y = counter_Y -1;
00285             counter_X_L = counter_X_L +1;
00286             counter_X_R = counter_X_R -1;
00287         }
00288     }
00289     if (distance  > 100 && distance <=150) {
00290         lcd.printString("Be Careful",12,0);
00291 
00292         while (counter_Y>=21) {
00293 
00294             for (int i = counter_Y; i<41; i++) {
00295                 lcd.setPixel(counter_X_L,i);
00296                 lcd.setPixel(counter_X_R,i);
00297             }
00298 
00299             counter_Y = counter_Y -1;
00300             counter_X_L = counter_X_L +1;
00301             counter_X_R = counter_X_R -1;
00302         }
00303     }
00304 
00305     if (distance  > 150 && distance <=200) {
00306         lcd.printString("Be Careful",12,0);
00307 
00308         while (counter_Y>=23) {
00309 
00310             for (int i = counter_Y; i<41; i++) {
00311                 lcd.setPixel(counter_X_L,i);
00312                 lcd.setPixel(counter_X_R,i);
00313             }
00314 
00315             counter_Y = counter_Y -1;
00316             counter_X_L = counter_X_L +1;
00317             counter_X_R = counter_X_R -1;
00318         }
00319     }
00320     if (distance  > 200 && distance <=250) {
00321         lcd.printString("***Move***",11,0);
00322 
00323         while (counter_Y>=25) {
00324 
00325             for (int i = counter_Y; i<41; i++) {
00326                 lcd.setPixel(counter_X_L,i);
00327                 lcd.setPixel(counter_X_R,i);
00328             }
00329 
00330             counter_Y = counter_Y -1;
00331             counter_X_L = counter_X_L +1;
00332             counter_X_R = counter_X_R -1;
00333         }
00334     }
00335     if (distance  > 250 && distance <=300) {
00336         lcd.printString("***Move***",11,0);
00337 
00338         while (counter_Y>=27) {
00339 
00340             for (int i = counter_Y; i<41; i++) {
00341                 lcd.setPixel(counter_X_L,i);
00342                 lcd.setPixel(counter_X_R,i);
00343             }
00344 
00345             counter_Y = counter_Y -1;
00346             counter_X_L = counter_X_L +1;
00347             counter_X_R = counter_X_R -1;
00348         }
00349     }
00350     if (distance  > 300 && distance <=350) {
00351         lcd.printString("***Move***",11,0);
00352 
00353         while (counter_Y>=29) {
00354 
00355             for (int i = counter_Y; i<41; i++) {
00356                 lcd.setPixel(counter_X_L,i);
00357                 lcd.setPixel(counter_X_R,i);
00358             }
00359 
00360             counter_Y = counter_Y -1;
00361             counter_X_L = counter_X_L +1;
00362             counter_X_R = counter_X_R -1;
00363         }
00364     }
00365     if (distance  > 350 && distance <=400) {
00366         lcd.printString("***Move***",11,0);
00367 
00368         while (counter_Y>=31) {
00369 
00370             for (int i = counter_Y; i<41; i++) {
00371                 lcd.setPixel(counter_X_L,i);
00372                 lcd.setPixel(counter_X_R,i);
00373             }
00374 
00375             counter_Y = counter_Y -1;
00376             counter_X_L = counter_X_L +1;
00377             counter_X_R = counter_X_R -1;
00378         }
00379 
00380     }
00381     if (distance  > 400 && distance <=450) {
00382         lcd.printString("***Move***",11,0);
00383 
00384         while (counter_Y>=33) {
00385 
00386             for (int i = counter_Y; i<41; i++) {
00387                 lcd.setPixel(counter_X_L,i);
00388                 lcd.setPixel(counter_X_R,i);
00389             }
00390 
00391             counter_Y = counter_Y -1;
00392             counter_X_L = counter_X_L +1;
00393             counter_X_R = counter_X_R -1;
00394         }
00395     }
00396     if (distance  > 450 && distance <=500) {
00397         lcd.printString("***Move***",11,0);
00398 
00399         while (counter_Y>=35) {
00400 
00401             for (int i = counter_Y; i<41; i++) {
00402                 lcd.setPixel(counter_X_L,i);
00403                 lcd.setPixel(counter_X_R,i);
00404             }
00405 
00406             counter_Y = counter_Y -1;
00407             counter_X_L = counter_X_L +1;
00408             counter_X_R = counter_X_R -1;
00409         }
00410     }
00411     if (distance  > 500 && distance <=550) {
00412         lcd.printString("***Move***",11,0);
00413 
00414         while (counter_Y>=37) {
00415 
00416             for (int i = counter_Y; i<41; i++) {
00417                 lcd.setPixel(counter_X_L,i);
00418                 lcd.setPixel(counter_X_R,i);
00419             }
00420 
00421             counter_Y = counter_Y -1;
00422             counter_X_L = counter_X_L +1;
00423             counter_X_R = counter_X_R -1;
00424         }
00425     }
00426     if (distance  > 550 && distance <=600) {
00427         lcd.printString("***Move***",11,0);
00428         lcd.setPixel(0,40);
00429         lcd.setPixel(1,40);
00430         lcd.setPixel(1,39);
00431         lcd.setPixel(83,40);
00432         lcd.setPixel(82,40);
00433         lcd.setPixel(82,39);
00434     }
00435     if (distance >600) {
00436         lcd.printString("*Out of range*",0,0);
00437         lcd.printString("Move",30,3);
00438     }
00439 }
00440 void buttonOperation_4()
00441 {
00442     //draw circles, lines and rectacular for the car on the NOKIA 5110 display
00443     lcd.drawCircle(15,37,7,1);
00444     lcd.drawLine(16,23,6,33,1);
00445     lcd.drawLine(0,35,35,35,1);
00446     lcd.drawLine(15,12,35,21,1);
00447     lcd.drawLine(35,34,35,21,1);
00448     lcd.drawLine(0,12,15,12,1);
00449     lcd.drawRect(3,16,11,6,0);
00450     lcd.drawLine(18,16,29,22,1);
00451     lcd.drawLine(18,15,18,22,1);
00452     lcd.drawLine(18,22,28,22,1);
00453     lcd.drawLine(16,14,16,23,1);
00454     lcd.drawLine(1,14,16,14,1);
00455     lcd.drawLine(1,14,1,33,1);
00456     lcd.drawLine(1,33,6,33,1);
00457     lcd.drawLine(1,23,16,23,1);
00458     lcd.drawCircle(40,33,2,1);
00459     lcd.drawRect(62,8,14,38,1);
00460 
00461   
00462     int length = sprintf(buffer ,"%.2fm",distance /100);
00463     if (length <= 5 && distance>= 16 && distance <= 600)  // if string and distance>=16 and distance<=600 will fit on display
00464         lcd.printString(buffer ,25,1);// display on screen
00465 
00466     if (distance < 16 ) {
00467         lcd.printString("Stop",30,1);// display on screen
00468         lcd.printString("YOU WILL CRASH",0,0);// display on screen
00469         lcd.drawLine(45,32,45,34,1);
00470         lcd.drawLine(48,30,48,36,1);
00471         lcd.drawLine(51,28,51,38,1);
00472         lcd.drawLine(54,26,54,40,1);
00473         lcd.drawLine(57,24,57,42,1);
00474         lcd.drawLine(60,22,60,44,1);
00475     }
00476 
00477     if (distance >=16 && distance  < 30) {
00478         lcd.printString("Stop",30,0);// display on screen
00479         //draw lines on the screen
00480         lcd.drawLine(45,32,45,34,1);
00481         lcd.drawLine(48,30,48,36,1);
00482         lcd.drawLine(51,28,51,38,1);
00483         lcd.drawLine(54,26,54,40,1);
00484         lcd.drawLine(57,24,57,42,1);
00485         lcd.drawLine(60,22,60,44,1);
00486     }
00487     if (distance  >= 30 && distance  < 100) {
00488         lcd.printString("***DANGER***",5,0);//display on the N5110 LCD
00489         lcd.drawLine(45,32,45,34,1);
00490         lcd.drawLine(48,30,48,36,1);
00491         lcd.drawLine(51,28,51,38,1);
00492         lcd.drawLine(54,26,54,40,1);
00493         lcd.drawLine(57,24,57,42,1);
00494     }
00495     if (distance  >= 100 && distance  <200 ) {
00496         lcd.printString("Be Careful",12,0);
00497         lcd.drawLine(45,32,45,34,1);
00498         lcd.drawLine(48,30,48,36,1);
00499         lcd.drawLine(51,28,51,38,1);
00500         lcd.drawLine(54,26,54,40,1);
00501     }
00502     if (distance  >= 200 && distance  <300 ) {
00503         lcd.printString("***Move***",11,0);
00504         lcd.drawLine(45,32,45,34,1);
00505         lcd.drawLine(48,30,48,36,1);
00506         lcd.drawLine(51,28,51,38,1);
00507     }
00508     if (distance  >= 300 && distance  <400 ) {
00509         lcd.printString("***Move***",11,0);
00510         lcd.drawLine(45,32,45,34,1);
00511         lcd.drawLine(48,30,48,36,1);
00512     }
00513     if (distance  >= 400 && distance  <=600 ) {
00514         lcd.printString("***Move***",11,0);
00515         lcd.drawLine(45,32,45,34,1);
00516     }
00517     if (distance  > 600) {
00518         lcd.printString("*Out of range*",0,0);
00519     }
00520 }
00521 
00522 void ButtonsOperation()
00523 {
00524     if (button3_flag  == 0 && button4_flag ==0)  { // check the status of the button 3 and 4
00525 
00526         buttonOperation_2(); // call function
00527     }
00528 
00529     if (button3_flag  == 1 && button4_flag ==0)  { // check the status of the button 3 and 4
00530 
00531         lcd.clear();//clear display
00532         lcd.refresh();//refresh display
00533         buttonOperation_3(); // call function
00534         button_4.rise(NULL); // button_4 becomes disable
00535         button_2.rise(NULL); // button_2 becomes disable
00536     }
00537 
00538     else
00539         button_4.rise(&button4_Pressed); // event generated on rising edge
00540     button_2.rise(&button2_Pressed); // event generated on rising edge
00541     lcd.refresh();
00542 
00543     if
00544     (button4_flag  == 1  && button3_flag ==0 ) {
00545 
00546         lcd.clear();
00547         lcd.refresh();
00548         buttonOperation_4();
00549         button_3.rise(NULL); // button_3 becomes disable
00550         button_2.rise(NULL); // button_2 becomes disable
00551 
00552 
00553     } else
00554         button_3.rise(&button3_Pressed); // event generated on rising edge
00555     button_2.rise(&button2_Pressed); // event generated on rising edge
00556     lcd.refresh();
00557 
00558 }
00559 
00560 int main()
00561 {
00562     lcd.init();//initialise display
00563     //set intial values of the leds
00564     led_red = 0;
00565     led_yellow=0;
00566     led_green=0;
00567     
00568     int result = semihost_powerdown();// power down the USB interface
00569 
00570     timer_red.attach(&timerExpired_red, 0.2); // call ISR every 0.2 seconds
00571     timer_yellow.attach(&timerExpired_yellow, 0.5); // call ISR every 0.5 seconds
00572     timer_green.attach(&timerExpired_green, 0.8); // call ISR every 0.8 seconds
00573 
00574     button_1.rise(&button1_Pressed); // event generated on rising edge
00575     button_2.rise(&button2_Pressed); // event generated on rising edge
00576     button_3.rise(&button3_Pressed); // event generated on rising edge
00577     button_4.rise(&button4_Pressed); // event generated on rising edge
00578 
00579     //set_time(1431299403); // initialise time to current time
00580 
00581     //print welcome messages
00582     lcd.printString("Parking_Sensor",0,0);//display on the N5110 LCD
00583     lcd.printString("By",35,2);//display on the N5110 LCD
00584     lcd.printString("Andreas",20,3);//display on the N5110 LCD
00585     lcd.printString("Konstantinou",5,4);//display on the N5110 LCD
00586 
00587     // draw lines and circles for the car on the right side of the display
00588     lcd.drawLine(83,20,83,14,1);
00589     lcd.drawLine(63,20,83,20,1);
00590     lcd.drawLine(63,20,63,14,1);
00591     lcd.drawLine(63,14,67,14,1);
00592     lcd.drawLine(67,14,73,10,1);
00593     lcd.drawLine(73,10,79,10,1);
00594     lcd.drawLine(79,10,83,14,1);
00595     lcd.drawCircle(67,20,2,1);
00596     lcd.drawCircle(79,20,2,1);
00597     // draw lines and circles for the car on the left side of the display
00598     lcd.drawLine(20,20,20,14,1);
00599     lcd.drawLine(0,20,20,20,1);
00600     lcd.drawLine(0,20,0,14,1);
00601     lcd.drawLine(0,14,4,14,1);
00602     lcd.drawLine(4,14,10,10,1);
00603     lcd.drawLine(10,10,16,10,1);
00604     lcd.drawLine(16,10,20,14,1);
00605     lcd.drawCircle(4,20,2,1);
00606     lcd.drawCircle(16,20,2,1);
00607 
00608     //draw lines for the road
00609     lcd.drawLine(0,41,83,41,1);
00610     lcd.drawLine(0,44,83,44,2);
00611     lcd.drawLine(0,47,83,47,1);
00612 
00613     wait(2.5);// 2.5 seconds delay
00614     lcd.clear();//clear the screen
00615     lcd.refresh();//refresh the display
00616 
00617     for (int j= 0; j>-83; j--) {
00618         lcd.printString("*University*",5,0);//display on the N5110 LCD
00619         lcd.printString("**Of Leeds**",5,1);//display on the N5110 LCD
00620         //draw lines for the road on the screen
00621         lcd.drawLine(0,30,83,30,1);
00622         lcd.drawLine(0,32,83,32,2);
00623         lcd.drawLine(0,35,83,35,1);
00624 
00625         // draw lines and circles for the cars on the display
00626         lcd.drawLine(83+j,30,83+j,24,1);
00627         lcd.drawLine(63+j,30,83+j,30,1);
00628         lcd.drawLine(63+j,30,63+j,24,1);
00629         lcd.drawLine(63+j,24,67+j,24,1);
00630         lcd.drawLine(67+j,24,73+j,20,1);
00631         lcd.drawLine(73+j,20,79+j,20,1);
00632         lcd.drawLine(79+j,20,83+j,24,1);
00633         lcd.drawCircle(67+j,30,2,1);
00634         lcd.drawCircle(79+j,30,2,1);
00635 
00636         lcd.drawLine(53+j,30,53+j,24,1);
00637         lcd.drawLine(33+j,30,53+j,30,1);
00638         lcd.drawLine(33+j,30,33+j,24,1);
00639         lcd.drawLine(33+j,24,37+j,24,1);
00640         lcd.drawLine(37+j,24,43+j,20,1);
00641         lcd.drawLine(43+j,20,49+j,20,1);
00642         lcd.drawLine(49+j,20,53+j,24,1);
00643         lcd.drawCircle(37+j,30,2,1);
00644         lcd.drawCircle(49+j,30,2,1);
00645 
00646         wait(0.10);//small delay
00647         lcd.clear();
00648         lcd.refresh();
00649     }
00650 
00651     while(1) {// infinite loop
00652        
00653        
00654         a1 =ain1.read(); // read the value of potentiometer
00655         lcd.setBrightness(a1 );// function to change LED backlight brightness using the potentiometer
00656         
00657         //call the functions
00658         Get_Average(); 
00659         ButtonsOperation();
00660         buttonOperation_1();
00661 
00662         Sleep();
00663     }
00664 }