Coding for vehicle rear assistant

Dependencies:   beep mbed

Fork of Vehicle_Rear_Assistant by amin omar

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 
00004 @brief Program implementation
00005 @brief Functions are called here when needed
00006 */
00007 #include "main.h"
00008                                     //main function
00009 int main ()
00010 {
00011     PHY_PowerDown();                        //Ethernet Power Down
00012     lcd.init();                             // the LCD display is initiated first when switch is on
00013     welcomeText();
00014     lcd.clear();
00015     button.rise(&buttonPressed);            //event generated on rising edge
00016     
00017     /// distance is measured in this loop
00018     while (1) {
00019         lcdBrightness = potBrightness;      //to adjust brightness using potentiometer
00020         getDistance();
00021         readDistance();
00022         lcd.clear();
00023      /// buttonFlag is set back to 0   
00024     if (buttonFlag ){                        //if flag is set = 1
00025         
00026         ///the value of displayReading is inverted
00027         displayReading  = ~displayReading ;   //if '~displayReading'(button is pushed again) value will not be dispayed 
00028         buttonFlag  = 0;                     // reset button back to 0
00029         }
00030         
00031         ///if the condition is meet, value of distance will be displayed
00032     if (displayReading ){                    //if 'displayReading'(button is pushed) value of distance is displayed
00033         int distance =sensor.getDistanceCm();
00034         char buffer[14];
00035         int length = sprintf(buffer,"D= %d cm",distance);
00036         if(length<=14)
00037         lcd.printString(buffer,7,1);
00038         lcd.drawRect(5,6,60,10,0);            //lcd.drawRect(76(x),0(y),7(w),48(h),1(type))>>>>box for distance value
00039         }
00040     }
00041 }
00042