Super Sensor

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 program main and its implementation
00004 @brief call functions here need one
00005 */
00006 
00007  #include "main.h"
00008 
00009 int main ()
00010 {
00011     PHY_PowerDown();  ///power down to minimise power usage 
00012     lcd.init();        ///nitialise lcd display
00013     welcomeMessage();  //print welcome message 
00014     lcd.clear();       //clear lcd
00015     
00016     button.rise(&buttonPressed);  //event generated on rising edge
00017     
00018     
00019    set_time(1431359340);   ///set time using UNIX time
00020 
00021     while(1) {
00022         ///potentiometer to control the lcd backlight
00023         if (potBrightness <= 0.1) {
00024             lcd.turnOff();
00025 
00026 
00027         }
00028         if (potBrightness >= 0.1) {
00029             lcd.init();
00030             lcdBrightness=potBrightness;
00031         }
00032         
00033         
00034         lcd.clear();
00035         getDistance();    ///sensor measure the distance
00036         
00037         ///print distance measure on the lcd 
00038         char buffer [14];
00039         int length = sprintf(buffer,"%d cm",distance );
00040         if (length<=14)
00041         lcd.printString(buffer, 22,1);  //print distance
00042         lcd.drawRect(20,6,45,10,0);     //box for value of distance on lcd
00043 
00044         
00045         ///if button is pressed, read distance (print car and wall)
00046         if (buttonFlag ) { //if flag is set = 1
00047 
00048             setTimeFlag  = ~setTimeFlag ;   //if button is pressed again, back to initial display
00049             buttonFlag  = 0;    //button flag is set to initial value
00050         }
00051 
00052         if (setTimeFlag ) {
00053              readDistance();  //draw car and obstacle
00054             
00055 
00056 
00057         } else {
00058            
00059             timeZone();  ///Display time & date to the user
00060 
00061 
00062         }
00063 
00064     }
00065 }
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078