Coding for vehicle rear assistant
Fork of Vehicle_Rear_Assistant by
Vehicle Rear Assistant ELEC 2645 el14a2o
main.cpp@0:53f28990602d, 2015-05-08 (annotated)
- Committer:
- aminomar
- Date:
- Fri May 08 21:54:44 2015 +0000
- Revision:
- 0:53f28990602d
code finished;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aminomar | 0:53f28990602d | 1 | /** |
aminomar | 0:53f28990602d | 2 | @file main.cpp |
aminomar | 0:53f28990602d | 3 | |
aminomar | 0:53f28990602d | 4 | @brief Program implementation |
aminomar | 0:53f28990602d | 5 | @brief Functions are called here when needed |
aminomar | 0:53f28990602d | 6 | */ |
aminomar | 0:53f28990602d | 7 | #include "main.h" |
aminomar | 0:53f28990602d | 8 | //main function |
aminomar | 0:53f28990602d | 9 | int main() |
aminomar | 0:53f28990602d | 10 | { |
aminomar | 0:53f28990602d | 11 | PHY_PowerDown(); //Ethernet Power Down |
aminomar | 0:53f28990602d | 12 | lcd.init(); // the LCD display is initiated first when switch is on |
aminomar | 0:53f28990602d | 13 | welcomeText(); |
aminomar | 0:53f28990602d | 14 | lcd.clear(); |
aminomar | 0:53f28990602d | 15 | button.rise(&buttonPressed); //event generated on rising edge |
aminomar | 0:53f28990602d | 16 | |
aminomar | 0:53f28990602d | 17 | /// distance is measured in this loop |
aminomar | 0:53f28990602d | 18 | while (1) { |
aminomar | 0:53f28990602d | 19 | lcdBrightness = potBrightness; //to adjust brightness using potentiometer |
aminomar | 0:53f28990602d | 20 | getDistance(); |
aminomar | 0:53f28990602d | 21 | readDistance(); |
aminomar | 0:53f28990602d | 22 | lcd.clear(); |
aminomar | 0:53f28990602d | 23 | /// buttonFlag is set back to 0 |
aminomar | 0:53f28990602d | 24 | if (buttonFlag){ //if flag is set = 1 |
aminomar | 0:53f28990602d | 25 | |
aminomar | 0:53f28990602d | 26 | ///the value of displayReading is inverted |
aminomar | 0:53f28990602d | 27 | displayReading = ~displayReading; //if '~displayReading'(button is pushed again) value will not be dispayed |
aminomar | 0:53f28990602d | 28 | buttonFlag = 0; // reset button back to 0 |
aminomar | 0:53f28990602d | 29 | } |
aminomar | 0:53f28990602d | 30 | |
aminomar | 0:53f28990602d | 31 | ///if the condition is meet, value of distance will be displayed |
aminomar | 0:53f28990602d | 32 | if (displayReading){ //if 'displayReading'(button is pushed) value of distance is displayed |
aminomar | 0:53f28990602d | 33 | int distance=sensor.getDistanceCm(); |
aminomar | 0:53f28990602d | 34 | char buffer[14]; |
aminomar | 0:53f28990602d | 35 | int length = sprintf(buffer,"D= %d cm",distance); |
aminomar | 0:53f28990602d | 36 | if(length<=14) |
aminomar | 0:53f28990602d | 37 | lcd.printString(buffer,7,1); |
aminomar | 0:53f28990602d | 38 | lcd.drawRect(5,6,60,10,0); //lcd.drawRect(76(x),0(y),7(w),48(h),1(type))>>>>box for distance value |
aminomar | 0:53f28990602d | 39 | } |
aminomar | 0:53f28990602d | 40 | } |
aminomar | 0:53f28990602d | 41 | } |
aminomar | 0:53f28990602d | 42 |