Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 PowerControl SRF02 beep mbed
main.cpp@0:f1120add03a8, 2015-05-11 (annotated)
- Committer:
- 200809780
- Date:
- Mon May 11 15:16:28 2015 +0000
- Revision:
- 0:f1120add03a8
Final
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| 200809780 | 0:f1120add03a8 | 1 | /** |
| 200809780 | 0:f1120add03a8 | 2 | @file main.cpp |
| 200809780 | 0:f1120add03a8 | 3 | @brief Reverse Parking Sensor Project |
| 200809780 | 0:f1120add03a8 | 4 | */ |
| 200809780 | 0:f1120add03a8 | 5 | |
| 200809780 | 0:f1120add03a8 | 6 | #include "main.h" |
| 200809780 | 0:f1120add03a8 | 7 | |
| 200809780 | 0:f1120add03a8 | 8 | void Get_Average() |
| 200809780 | 0:f1120add03a8 | 9 | { |
| 200809780 | 0:f1120add03a8 | 10 | distance =0;//set the distance to 0 |
| 200809780 | 0:f1120add03a8 | 11 | int counter =0; //set the counter to 0 |
| 200809780 | 0:f1120add03a8 | 12 | |
| 200809780 | 0:f1120add03a8 | 13 | //for loop to store 5 sensor's values |
| 200809780 | 0:f1120add03a8 | 14 | for ( counter =0; counter<5; counter++) { |
| 200809780 | 0:f1120add03a8 | 15 | |
| 200809780 | 0:f1120add03a8 | 16 | Distance_Array [counter] =srf02.getDistanceCm(); //store the value of the sensor in the array |
| 200809780 | 0:f1120add03a8 | 17 | } |
| 200809780 | 0:f1120add03a8 | 18 | |
| 200809780 | 0:f1120add03a8 | 19 | 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 |
| 200809780 | 0:f1120add03a8 | 20 | } |
| 200809780 | 0:f1120add03a8 | 21 | |
| 200809780 | 0:f1120add03a8 | 22 | //set power down the USB interface |
| 200809780 | 0:f1120add03a8 | 23 | int semihost_powerdown() |
| 200809780 | 0:f1120add03a8 | 24 | { |
| 200809780 | 0:f1120add03a8 | 25 | uint32_t arg; |
| 200809780 | 0:f1120add03a8 | 26 | return __semihost(USR_POWERDOWN, &arg); |
| 200809780 | 0:f1120add03a8 | 27 | |
| 200809780 | 0:f1120add03a8 | 28 | } |
| 200809780 | 0:f1120add03a8 | 29 | |
| 200809780 | 0:f1120add03a8 | 30 | //Interrupt Service Routine |
| 200809780 | 0:f1120add03a8 | 31 | void button1_Pressed() |
| 200809780 | 0:f1120add03a8 | 32 | { |
| 200809780 | 0:f1120add03a8 | 33 | button1_flag = !button1_flag; //set flag |
| 200809780 | 0:f1120add03a8 | 34 | } |
| 200809780 | 0:f1120add03a8 | 35 | void button2_Pressed() |
| 200809780 | 0:f1120add03a8 | 36 | { |
| 200809780 | 0:f1120add03a8 | 37 | button2_flag = !button2_flag; //set flag |
| 200809780 | 0:f1120add03a8 | 38 | } |
| 200809780 | 0:f1120add03a8 | 39 | void button3_Pressed() |
| 200809780 | 0:f1120add03a8 | 40 | { |
| 200809780 | 0:f1120add03a8 | 41 | button3_flag = !button3_flag; //set flag |
| 200809780 | 0:f1120add03a8 | 42 | } |
| 200809780 | 0:f1120add03a8 | 43 | void button4_Pressed() |
| 200809780 | 0:f1120add03a8 | 44 | { |
| 200809780 | 0:f1120add03a8 | 45 | button4_flag = !button4_flag; //set flag |
| 200809780 | 0:f1120add03a8 | 46 | } |
| 200809780 | 0:f1120add03a8 | 47 | |
| 200809780 | 0:f1120add03a8 | 48 | void Print_Time_Date() |
| 200809780 | 0:f1120add03a8 | 49 | { |
| 200809780 | 0:f1120add03a8 | 50 | char buffer_time_lcd[14];// buffer to store the time into the 14 characters each char has 6 pixels,so 84/6 = 14 |
| 200809780 | 0:f1120add03a8 | 51 | char buffer_date_lcd[14]; |
| 200809780 | 0:f1120add03a8 | 52 | time_t seconds = time(NULL); // get current time |
| 200809780 | 0:f1120add03a8 | 53 | |
| 200809780 | 0:f1120add03a8 | 54 | // format time and date into 2 strings (time and date) |
| 200809780 | 0:f1120add03a8 | 55 | strftime(buffer_time_lcd, 14 , "%r",localtime(&seconds)); |
| 200809780 | 0:f1120add03a8 | 56 | strftime(buffer_date_lcd, 14 , "%d %b %G ",localtime(&seconds)); |
| 200809780 | 0:f1120add03a8 | 57 | |
| 200809780 | 0:f1120add03a8 | 58 | // print current date and time value on the LCD |
| 200809780 | 0:f1120add03a8 | 59 | lcd.printString(buffer_time_lcd,0,4); |
| 200809780 | 0:f1120add03a8 | 60 | lcd.printString(buffer_date_lcd,0,5); |
| 200809780 | 0:f1120add03a8 | 61 | } |
| 200809780 | 0:f1120add03a8 | 62 | |
| 200809780 | 0:f1120add03a8 | 63 | // Interrupt Service Routine |
| 200809780 | 0:f1120add03a8 | 64 | void timerExpired_red() |
| 200809780 | 0:f1120add03a8 | 65 | { |
| 200809780 | 0:f1120add03a8 | 66 | timerflag_red = 1; // set flag |
| 200809780 | 0:f1120add03a8 | 67 | } |
| 200809780 | 0:f1120add03a8 | 68 | |
| 200809780 | 0:f1120add03a8 | 69 | void timerExpired_yellow() |
| 200809780 | 0:f1120add03a8 | 70 | { |
| 200809780 | 0:f1120add03a8 | 71 | timerflag_yellow= 1; // set flag |
| 200809780 | 0:f1120add03a8 | 72 | } |
| 200809780 | 0:f1120add03a8 | 73 | |
| 200809780 | 0:f1120add03a8 | 74 | void timerExpired_green() |
| 200809780 | 0:f1120add03a8 | 75 | { |
| 200809780 | 0:f1120add03a8 | 76 | timerflag_green = 1; // set flag |
| 200809780 | 0:f1120add03a8 | 77 | } |
| 200809780 | 0:f1120add03a8 | 78 | |
| 200809780 | 0:f1120add03a8 | 79 | void buttonOperation_1() |
| 200809780 | 0:f1120add03a8 | 80 | { |
| 200809780 | 0:f1120add03a8 | 81 | // if button1 is pressed |
| 200809780 | 0:f1120add03a8 | 82 | if (button1_flag) { |
| 200809780 | 0:f1120add03a8 | 83 | a2=ain2.read(); // read value of potentiometer |
| 200809780 | 0:f1120add03a8 | 84 | if (distance <= 16) { |
| 200809780 | 0:f1120add03a8 | 85 | //set the values of leds |
| 200809780 | 0:f1120add03a8 | 86 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 87 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 88 | led_red = 1; |
| 200809780 | 0:f1120add03a8 | 89 | buzzer.beep(500+a2*1000,2.0);// buzzer makes sound with a delay of 2 seconds |
| 200809780 | 0:f1120add03a8 | 90 | } |
| 200809780 | 0:f1120add03a8 | 91 | if (distance > 16 && distance < 100) { |
| 200809780 | 0:f1120add03a8 | 92 | if (timerflag_red) { // if flag is set |
| 200809780 | 0:f1120add03a8 | 93 | timerflag_red = 0; // reset flag |
| 200809780 | 0:f1120add03a8 | 94 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 95 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 96 | led_red = ! led_red; |
| 200809780 | 0:f1120add03a8 | 97 | buzzer.beep(500+a2*1000,0.2);// buzzer makes sound with a delay of 2 seconds |
| 200809780 | 0:f1120add03a8 | 98 | } |
| 200809780 | 0:f1120add03a8 | 99 | } |
| 200809780 | 0:f1120add03a8 | 100 | if(distance >= 100 && distance < 300) { |
| 200809780 | 0:f1120add03a8 | 101 | if (timerflag_yellow) { // if flag is set |
| 200809780 | 0:f1120add03a8 | 102 | timerflag_yellow = 0; // reset flag |
| 200809780 | 0:f1120add03a8 | 103 | led_red =0; |
| 200809780 | 0:f1120add03a8 | 104 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 105 | led_yellow = ! led_yellow; |
| 200809780 | 0:f1120add03a8 | 106 | buzzer.beep(500+a2*1000,0.5); // buzzer makes sound with a delay of 0.5 seconds |
| 200809780 | 0:f1120add03a8 | 107 | } |
| 200809780 | 0:f1120add03a8 | 108 | } |
| 200809780 | 0:f1120add03a8 | 109 | |
| 200809780 | 0:f1120add03a8 | 110 | if (distance >= 300 && distance <=600 ) { |
| 200809780 | 0:f1120add03a8 | 111 | if (timerflag_green) { // if flag is set |
| 200809780 | 0:f1120add03a8 | 112 | timerflag_green = 0; // reset flag |
| 200809780 | 0:f1120add03a8 | 113 | led_red =0; |
| 200809780 | 0:f1120add03a8 | 114 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 115 | led_green = ! led_green; |
| 200809780 | 0:f1120add03a8 | 116 | buzzer.beep(500+a2*1000,0.8); // buzzer makes sound with a delay of 0.5 seconds |
| 200809780 | 0:f1120add03a8 | 117 | } |
| 200809780 | 0:f1120add03a8 | 118 | } |
| 200809780 | 0:f1120add03a8 | 119 | |
| 200809780 | 0:f1120add03a8 | 120 | if (distance >600 ) { |
| 200809780 | 0:f1120add03a8 | 121 | led_red =0; |
| 200809780 | 0:f1120add03a8 | 122 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 123 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 124 | } |
| 200809780 | 0:f1120add03a8 | 125 | } |
| 200809780 | 0:f1120add03a8 | 126 | |
| 200809780 | 0:f1120add03a8 | 127 | else { |
| 200809780 | 0:f1120add03a8 | 128 | if (distance < 100) { |
| 200809780 | 0:f1120add03a8 | 129 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 130 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 131 | led_red = 1; |
| 200809780 | 0:f1120add03a8 | 132 | } else |
| 200809780 | 0:f1120add03a8 | 133 | led_red =0; |
| 200809780 | 0:f1120add03a8 | 134 | |
| 200809780 | 0:f1120add03a8 | 135 | |
| 200809780 | 0:f1120add03a8 | 136 | if (distance >= 100 && distance < 300) { |
| 200809780 | 0:f1120add03a8 | 137 | led_red =0; |
| 200809780 | 0:f1120add03a8 | 138 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 139 | led_yellow = 1; |
| 200809780 | 0:f1120add03a8 | 140 | } else |
| 200809780 | 0:f1120add03a8 | 141 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 142 | |
| 200809780 | 0:f1120add03a8 | 143 | if (distance >= 300 && distance <=600 ) { |
| 200809780 | 0:f1120add03a8 | 144 | led_red =0; |
| 200809780 | 0:f1120add03a8 | 145 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 146 | led_green = 1; |
| 200809780 | 0:f1120add03a8 | 147 | } else |
| 200809780 | 0:f1120add03a8 | 148 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 149 | |
| 200809780 | 0:f1120add03a8 | 150 | if (distance >600 ) { |
| 200809780 | 0:f1120add03a8 | 151 | led_red =0; |
| 200809780 | 0:f1120add03a8 | 152 | led_yellow =0; |
| 200809780 | 0:f1120add03a8 | 153 | led_green =0; |
| 200809780 | 0:f1120add03a8 | 154 | } |
| 200809780 | 0:f1120add03a8 | 155 | } |
| 200809780 | 0:f1120add03a8 | 156 | } |
| 200809780 | 0:f1120add03a8 | 157 | |
| 200809780 | 0:f1120add03a8 | 158 | void buttonOperation_2() |
| 200809780 | 0:f1120add03a8 | 159 | { |
| 200809780 | 0:f1120add03a8 | 160 | |
| 200809780 | 0:f1120add03a8 | 161 | if (button2_flag==0 && button3_flag==0 && button4_flag==0) { |
| 200809780 | 0:f1120add03a8 | 162 | |
| 200809780 | 0:f1120add03a8 | 163 | int length = sprintf(buffer,"%.fcm",distance); // print formatted data to buffer |
| 200809780 | 0:f1120add03a8 | 164 | // it is important the format specifier ensures the length will fit in the buffer |
| 200809780 | 0:f1120add03a8 | 165 | if (length == 5 ) { // if string will fit on display |
| 200809780 | 0:f1120add03a8 | 166 | |
| 200809780 | 0:f1120add03a8 | 167 | lcd.clear(); // clear LCD |
| 200809780 | 0:f1120add03a8 | 168 | lcd.refresh(); // refresh LCD |
| 200809780 | 0:f1120add03a8 | 169 | lcd.printString(buffer,25,2);// display on screen |
| 200809780 | 0:f1120add03a8 | 170 | } |
| 200809780 | 0:f1120add03a8 | 171 | |
| 200809780 | 0:f1120add03a8 | 172 | if (length < 5 ) { // if string will fit on display |
| 200809780 | 0:f1120add03a8 | 173 | lcd.clear(); |
| 200809780 | 0:f1120add03a8 | 174 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 175 | lcd.printString(buffer,29,2);// display on screen |
| 200809780 | 0:f1120add03a8 | 176 | } |
| 200809780 | 0:f1120add03a8 | 177 | } |
| 200809780 | 0:f1120add03a8 | 178 | |
| 200809780 | 0:f1120add03a8 | 179 | if (button2_flag==1 && button3_flag==0 && button4_flag==0) { |
| 200809780 | 0:f1120add03a8 | 180 | |
| 200809780 | 0:f1120add03a8 | 181 | int length = sprintf(buffer,"%.2fm",distance/100); |
| 200809780 | 0:f1120add03a8 | 182 | if (length <= 5) { // if string will fit on display |
| 200809780 | 0:f1120add03a8 | 183 | lcd.clear(); |
| 200809780 | 0:f1120add03a8 | 184 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 185 | lcd.printString(buffer,26,2);// display on screen |
| 200809780 | 0:f1120add03a8 | 186 | } |
| 200809780 | 0:f1120add03a8 | 187 | |
| 200809780 | 0:f1120add03a8 | 188 | } |
| 200809780 | 0:f1120add03a8 | 189 | |
| 200809780 | 0:f1120add03a8 | 190 | if (distance < 16) { |
| 200809780 | 0:f1120add03a8 | 191 | lcd.clear(); |
| 200809780 | 0:f1120add03a8 | 192 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 193 | lcd.printString("STOP",28,2); |
| 200809780 | 0:f1120add03a8 | 194 | lcd.printString("YOU WILL CRASH",0,0); |
| 200809780 | 0:f1120add03a8 | 195 | |
| 200809780 | 0:f1120add03a8 | 196 | } |
| 200809780 | 0:f1120add03a8 | 197 | |
| 200809780 | 0:f1120add03a8 | 198 | if (distance < 100 && distance >=16) { |
| 200809780 | 0:f1120add03a8 | 199 | |
| 200809780 | 0:f1120add03a8 | 200 | lcd.printString("***DANGER***",5,0);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 201 | } |
| 200809780 | 0:f1120add03a8 | 202 | |
| 200809780 | 0:f1120add03a8 | 203 | else if (distance >= 100 && distance <300) { |
| 200809780 | 0:f1120add03a8 | 204 | |
| 200809780 | 0:f1120add03a8 | 205 | lcd.printString("Be Careful",12,0); |
| 200809780 | 0:f1120add03a8 | 206 | |
| 200809780 | 0:f1120add03a8 | 207 | } else if (distance >= 300 && distance <=600) { |
| 200809780 | 0:f1120add03a8 | 208 | |
| 200809780 | 0:f1120add03a8 | 209 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 210 | } |
| 200809780 | 0:f1120add03a8 | 211 | |
| 200809780 | 0:f1120add03a8 | 212 | else if (distance > 600) { |
| 200809780 | 0:f1120add03a8 | 213 | |
| 200809780 | 0:f1120add03a8 | 214 | lcd.clear(); |
| 200809780 | 0:f1120add03a8 | 215 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 216 | lcd.printString("*Out of range*",0,0); |
| 200809780 | 0:f1120add03a8 | 217 | lcd.printString("MOVE",28,2); |
| 200809780 | 0:f1120add03a8 | 218 | } |
| 200809780 | 0:f1120add03a8 | 219 | |
| 200809780 | 0:f1120add03a8 | 220 | //draw rectacular and lines on the screen |
| 200809780 | 0:f1120add03a8 | 221 | lcd.drawRect(20,10,40,18,0); |
| 200809780 | 0:f1120add03a8 | 222 | lcd.drawRect(21,11,38,16,0); |
| 200809780 | 0:f1120add03a8 | 223 | lcd.drawRect(22,12,36,14,0); |
| 200809780 | 0:f1120add03a8 | 224 | lcd.drawLine(0,19,20,19,1); |
| 200809780 | 0:f1120add03a8 | 225 | lcd.drawLine(60,19,83,19,1); |
| 200809780 | 0:f1120add03a8 | 226 | //call the function |
| 200809780 | 0:f1120add03a8 | 227 | Print_Time_Date(); |
| 200809780 | 0:f1120add03a8 | 228 | |
| 200809780 | 0:f1120add03a8 | 229 | } |
| 200809780 | 0:f1120add03a8 | 230 | void buttonOperation_3() |
| 200809780 | 0:f1120add03a8 | 231 | { |
| 200809780 | 0:f1120add03a8 | 232 | |
| 200809780 | 0:f1120add03a8 | 233 | int length = sprintf(buffer,"%.2fm",distance/100); // print formatted data to buffer |
| 200809780 | 0:f1120add03a8 | 234 | // it is important the format specifier ensures the length will fit in the buffer |
| 200809780 | 0:f1120add03a8 | 235 | if (length <= 5 && distance>=16 && distance<=600) { // if string will fit on display |
| 200809780 | 0:f1120add03a8 | 236 | lcd.printString(buffer,28,3); |
| 200809780 | 0:f1120add03a8 | 237 | } |
| 200809780 | 0:f1120add03a8 | 238 | |
| 200809780 | 0:f1120add03a8 | 239 | int counter_Y = 40;//initial variable for the y-axes of the screen |
| 200809780 | 0:f1120add03a8 | 240 | int counter_X_L = 0; // initial variable for the x-axes on the left side of the screen |
| 200809780 | 0:f1120add03a8 | 241 | int counter_X_R = 83;// initial variable for the x-axes on the right side of the screen |
| 200809780 | 0:f1120add03a8 | 242 | |
| 200809780 | 0:f1120add03a8 | 243 | if (distance < 16) { |
| 200809780 | 0:f1120add03a8 | 244 | lcd.printString("STOP",30,3); |
| 200809780 | 0:f1120add03a8 | 245 | lcd.printString("YOU WILL CRASH",0,0); |
| 200809780 | 0:f1120add03a8 | 246 | |
| 200809780 | 0:f1120add03a8 | 247 | while (counter_Y>=15) { |
| 200809780 | 0:f1120add03a8 | 248 | // for loop to set the pixels |
| 200809780 | 0:f1120add03a8 | 249 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 250 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 251 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 252 | } |
| 200809780 | 0:f1120add03a8 | 253 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 254 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 255 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 256 | } |
| 200809780 | 0:f1120add03a8 | 257 | } |
| 200809780 | 0:f1120add03a8 | 258 | |
| 200809780 | 0:f1120add03a8 | 259 | if (distance >= 16 && distance <= 40) { |
| 200809780 | 0:f1120add03a8 | 260 | lcd.printString("***DANGER***",5,0);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 261 | |
| 200809780 | 0:f1120add03a8 | 262 | while (counter_Y>=17) { |
| 200809780 | 0:f1120add03a8 | 263 | |
| 200809780 | 0:f1120add03a8 | 264 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 265 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 266 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 267 | } |
| 200809780 | 0:f1120add03a8 | 268 | |
| 200809780 | 0:f1120add03a8 | 269 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 270 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 271 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 272 | } |
| 200809780 | 0:f1120add03a8 | 273 | } |
| 200809780 | 0:f1120add03a8 | 274 | if (distance > 40 && distance <= 100) { |
| 200809780 | 0:f1120add03a8 | 275 | lcd.printString("***DANGER***",5,0); |
| 200809780 | 0:f1120add03a8 | 276 | |
| 200809780 | 0:f1120add03a8 | 277 | while (counter_Y>=19) { |
| 200809780 | 0:f1120add03a8 | 278 | |
| 200809780 | 0:f1120add03a8 | 279 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 280 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 281 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 282 | } |
| 200809780 | 0:f1120add03a8 | 283 | |
| 200809780 | 0:f1120add03a8 | 284 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 285 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 286 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 287 | } |
| 200809780 | 0:f1120add03a8 | 288 | } |
| 200809780 | 0:f1120add03a8 | 289 | if (distance > 100 && distance<=150) { |
| 200809780 | 0:f1120add03a8 | 290 | lcd.printString("Be Careful",12,0); |
| 200809780 | 0:f1120add03a8 | 291 | |
| 200809780 | 0:f1120add03a8 | 292 | while (counter_Y>=21) { |
| 200809780 | 0:f1120add03a8 | 293 | |
| 200809780 | 0:f1120add03a8 | 294 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 295 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 296 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 297 | } |
| 200809780 | 0:f1120add03a8 | 298 | |
| 200809780 | 0:f1120add03a8 | 299 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 300 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 301 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 302 | } |
| 200809780 | 0:f1120add03a8 | 303 | } |
| 200809780 | 0:f1120add03a8 | 304 | |
| 200809780 | 0:f1120add03a8 | 305 | if (distance > 150 && distance<=200) { |
| 200809780 | 0:f1120add03a8 | 306 | lcd.printString("Be Careful",12,0); |
| 200809780 | 0:f1120add03a8 | 307 | |
| 200809780 | 0:f1120add03a8 | 308 | while (counter_Y>=23) { |
| 200809780 | 0:f1120add03a8 | 309 | |
| 200809780 | 0:f1120add03a8 | 310 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 311 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 312 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 313 | } |
| 200809780 | 0:f1120add03a8 | 314 | |
| 200809780 | 0:f1120add03a8 | 315 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 316 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 317 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 318 | } |
| 200809780 | 0:f1120add03a8 | 319 | } |
| 200809780 | 0:f1120add03a8 | 320 | if (distance > 200 && distance<=250) { |
| 200809780 | 0:f1120add03a8 | 321 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 322 | |
| 200809780 | 0:f1120add03a8 | 323 | while (counter_Y>=25) { |
| 200809780 | 0:f1120add03a8 | 324 | |
| 200809780 | 0:f1120add03a8 | 325 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 326 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 327 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 328 | } |
| 200809780 | 0:f1120add03a8 | 329 | |
| 200809780 | 0:f1120add03a8 | 330 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 331 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 332 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 333 | } |
| 200809780 | 0:f1120add03a8 | 334 | } |
| 200809780 | 0:f1120add03a8 | 335 | if (distance > 250 && distance<=300) { |
| 200809780 | 0:f1120add03a8 | 336 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 337 | |
| 200809780 | 0:f1120add03a8 | 338 | while (counter_Y>=27) { |
| 200809780 | 0:f1120add03a8 | 339 | |
| 200809780 | 0:f1120add03a8 | 340 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 341 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 342 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 343 | } |
| 200809780 | 0:f1120add03a8 | 344 | |
| 200809780 | 0:f1120add03a8 | 345 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 346 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 347 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 348 | } |
| 200809780 | 0:f1120add03a8 | 349 | } |
| 200809780 | 0:f1120add03a8 | 350 | if (distance > 300 && distance<=350) { |
| 200809780 | 0:f1120add03a8 | 351 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 352 | |
| 200809780 | 0:f1120add03a8 | 353 | while (counter_Y>=29) { |
| 200809780 | 0:f1120add03a8 | 354 | |
| 200809780 | 0:f1120add03a8 | 355 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 356 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 357 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 358 | } |
| 200809780 | 0:f1120add03a8 | 359 | |
| 200809780 | 0:f1120add03a8 | 360 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 361 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 362 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 363 | } |
| 200809780 | 0:f1120add03a8 | 364 | } |
| 200809780 | 0:f1120add03a8 | 365 | if (distance > 350 && distance<=400) { |
| 200809780 | 0:f1120add03a8 | 366 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 367 | |
| 200809780 | 0:f1120add03a8 | 368 | while (counter_Y>=31) { |
| 200809780 | 0:f1120add03a8 | 369 | |
| 200809780 | 0:f1120add03a8 | 370 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 371 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 372 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 373 | } |
| 200809780 | 0:f1120add03a8 | 374 | |
| 200809780 | 0:f1120add03a8 | 375 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 376 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 377 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 378 | } |
| 200809780 | 0:f1120add03a8 | 379 | |
| 200809780 | 0:f1120add03a8 | 380 | } |
| 200809780 | 0:f1120add03a8 | 381 | if (distance > 400 && distance<=450) { |
| 200809780 | 0:f1120add03a8 | 382 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 383 | |
| 200809780 | 0:f1120add03a8 | 384 | while (counter_Y>=33) { |
| 200809780 | 0:f1120add03a8 | 385 | |
| 200809780 | 0:f1120add03a8 | 386 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 387 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 388 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 389 | } |
| 200809780 | 0:f1120add03a8 | 390 | |
| 200809780 | 0:f1120add03a8 | 391 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 392 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 393 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 394 | } |
| 200809780 | 0:f1120add03a8 | 395 | } |
| 200809780 | 0:f1120add03a8 | 396 | if (distance > 450 && distance<=500) { |
| 200809780 | 0:f1120add03a8 | 397 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 398 | |
| 200809780 | 0:f1120add03a8 | 399 | while (counter_Y>=35) { |
| 200809780 | 0:f1120add03a8 | 400 | |
| 200809780 | 0:f1120add03a8 | 401 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 402 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 403 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 404 | } |
| 200809780 | 0:f1120add03a8 | 405 | |
| 200809780 | 0:f1120add03a8 | 406 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 407 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 408 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 409 | } |
| 200809780 | 0:f1120add03a8 | 410 | } |
| 200809780 | 0:f1120add03a8 | 411 | if (distance > 500 && distance<=550) { |
| 200809780 | 0:f1120add03a8 | 412 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 413 | |
| 200809780 | 0:f1120add03a8 | 414 | while (counter_Y>=37) { |
| 200809780 | 0:f1120add03a8 | 415 | |
| 200809780 | 0:f1120add03a8 | 416 | for (int i = counter_Y; i<41; i++) { |
| 200809780 | 0:f1120add03a8 | 417 | lcd.setPixel(counter_X_L,i); |
| 200809780 | 0:f1120add03a8 | 418 | lcd.setPixel(counter_X_R,i); |
| 200809780 | 0:f1120add03a8 | 419 | } |
| 200809780 | 0:f1120add03a8 | 420 | |
| 200809780 | 0:f1120add03a8 | 421 | counter_Y = counter_Y -1; |
| 200809780 | 0:f1120add03a8 | 422 | counter_X_L = counter_X_L +1; |
| 200809780 | 0:f1120add03a8 | 423 | counter_X_R = counter_X_R -1; |
| 200809780 | 0:f1120add03a8 | 424 | } |
| 200809780 | 0:f1120add03a8 | 425 | } |
| 200809780 | 0:f1120add03a8 | 426 | if (distance > 550 && distance<=600) { |
| 200809780 | 0:f1120add03a8 | 427 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 428 | lcd.setPixel(0,40); |
| 200809780 | 0:f1120add03a8 | 429 | lcd.setPixel(1,40); |
| 200809780 | 0:f1120add03a8 | 430 | lcd.setPixel(1,39); |
| 200809780 | 0:f1120add03a8 | 431 | lcd.setPixel(83,40); |
| 200809780 | 0:f1120add03a8 | 432 | lcd.setPixel(82,40); |
| 200809780 | 0:f1120add03a8 | 433 | lcd.setPixel(82,39); |
| 200809780 | 0:f1120add03a8 | 434 | } |
| 200809780 | 0:f1120add03a8 | 435 | if (distance>600) { |
| 200809780 | 0:f1120add03a8 | 436 | lcd.printString("*Out of range*",0,0); |
| 200809780 | 0:f1120add03a8 | 437 | lcd.printString("Move",30,3); |
| 200809780 | 0:f1120add03a8 | 438 | } |
| 200809780 | 0:f1120add03a8 | 439 | } |
| 200809780 | 0:f1120add03a8 | 440 | void buttonOperation_4() |
| 200809780 | 0:f1120add03a8 | 441 | { |
| 200809780 | 0:f1120add03a8 | 442 | //draw circles, lines and rectacular for the car on the NOKIA 5110 display |
| 200809780 | 0:f1120add03a8 | 443 | lcd.drawCircle(15,37,7,1); |
| 200809780 | 0:f1120add03a8 | 444 | lcd.drawLine(16,23,6,33,1); |
| 200809780 | 0:f1120add03a8 | 445 | lcd.drawLine(0,35,35,35,1); |
| 200809780 | 0:f1120add03a8 | 446 | lcd.drawLine(15,12,35,21,1); |
| 200809780 | 0:f1120add03a8 | 447 | lcd.drawLine(35,34,35,21,1); |
| 200809780 | 0:f1120add03a8 | 448 | lcd.drawLine(0,12,15,12,1); |
| 200809780 | 0:f1120add03a8 | 449 | lcd.drawRect(3,16,11,6,0); |
| 200809780 | 0:f1120add03a8 | 450 | lcd.drawLine(18,16,29,22,1); |
| 200809780 | 0:f1120add03a8 | 451 | lcd.drawLine(18,15,18,22,1); |
| 200809780 | 0:f1120add03a8 | 452 | lcd.drawLine(18,22,28,22,1); |
| 200809780 | 0:f1120add03a8 | 453 | lcd.drawLine(16,14,16,23,1); |
| 200809780 | 0:f1120add03a8 | 454 | lcd.drawLine(1,14,16,14,1); |
| 200809780 | 0:f1120add03a8 | 455 | lcd.drawLine(1,14,1,33,1); |
| 200809780 | 0:f1120add03a8 | 456 | lcd.drawLine(1,33,6,33,1); |
| 200809780 | 0:f1120add03a8 | 457 | lcd.drawLine(1,23,16,23,1); |
| 200809780 | 0:f1120add03a8 | 458 | lcd.drawCircle(40,33,2,1); |
| 200809780 | 0:f1120add03a8 | 459 | lcd.drawRect(62,8,14,38,1); |
| 200809780 | 0:f1120add03a8 | 460 | |
| 200809780 | 0:f1120add03a8 | 461 | |
| 200809780 | 0:f1120add03a8 | 462 | int length = sprintf(buffer,"%.2fm",distance/100); |
| 200809780 | 0:f1120add03a8 | 463 | if (length <= 5 && distance>= 16 && distance<= 600) // if string and distance>=16 and distance<=600 will fit on display |
| 200809780 | 0:f1120add03a8 | 464 | lcd.printString(buffer,25,1);// display on screen |
| 200809780 | 0:f1120add03a8 | 465 | |
| 200809780 | 0:f1120add03a8 | 466 | if (distance< 16 ) { |
| 200809780 | 0:f1120add03a8 | 467 | lcd.printString("Stop",30,1);// display on screen |
| 200809780 | 0:f1120add03a8 | 468 | lcd.printString("YOU WILL CRASH",0,0);// display on screen |
| 200809780 | 0:f1120add03a8 | 469 | lcd.drawLine(45,32,45,34,1); |
| 200809780 | 0:f1120add03a8 | 470 | lcd.drawLine(48,30,48,36,1); |
| 200809780 | 0:f1120add03a8 | 471 | lcd.drawLine(51,28,51,38,1); |
| 200809780 | 0:f1120add03a8 | 472 | lcd.drawLine(54,26,54,40,1); |
| 200809780 | 0:f1120add03a8 | 473 | lcd.drawLine(57,24,57,42,1); |
| 200809780 | 0:f1120add03a8 | 474 | lcd.drawLine(60,22,60,44,1); |
| 200809780 | 0:f1120add03a8 | 475 | } |
| 200809780 | 0:f1120add03a8 | 476 | |
| 200809780 | 0:f1120add03a8 | 477 | if (distance>=16 && distance < 30) { |
| 200809780 | 0:f1120add03a8 | 478 | lcd.printString("Stop",30,0);// display on screen |
| 200809780 | 0:f1120add03a8 | 479 | //draw lines on the screen |
| 200809780 | 0:f1120add03a8 | 480 | lcd.drawLine(45,32,45,34,1); |
| 200809780 | 0:f1120add03a8 | 481 | lcd.drawLine(48,30,48,36,1); |
| 200809780 | 0:f1120add03a8 | 482 | lcd.drawLine(51,28,51,38,1); |
| 200809780 | 0:f1120add03a8 | 483 | lcd.drawLine(54,26,54,40,1); |
| 200809780 | 0:f1120add03a8 | 484 | lcd.drawLine(57,24,57,42,1); |
| 200809780 | 0:f1120add03a8 | 485 | lcd.drawLine(60,22,60,44,1); |
| 200809780 | 0:f1120add03a8 | 486 | } |
| 200809780 | 0:f1120add03a8 | 487 | if (distance >= 30 && distance < 100) { |
| 200809780 | 0:f1120add03a8 | 488 | lcd.printString("***DANGER***",5,0);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 489 | lcd.drawLine(45,32,45,34,1); |
| 200809780 | 0:f1120add03a8 | 490 | lcd.drawLine(48,30,48,36,1); |
| 200809780 | 0:f1120add03a8 | 491 | lcd.drawLine(51,28,51,38,1); |
| 200809780 | 0:f1120add03a8 | 492 | lcd.drawLine(54,26,54,40,1); |
| 200809780 | 0:f1120add03a8 | 493 | lcd.drawLine(57,24,57,42,1); |
| 200809780 | 0:f1120add03a8 | 494 | } |
| 200809780 | 0:f1120add03a8 | 495 | if (distance >= 100 && distance <200 ) { |
| 200809780 | 0:f1120add03a8 | 496 | lcd.printString("Be Careful",12,0); |
| 200809780 | 0:f1120add03a8 | 497 | lcd.drawLine(45,32,45,34,1); |
| 200809780 | 0:f1120add03a8 | 498 | lcd.drawLine(48,30,48,36,1); |
| 200809780 | 0:f1120add03a8 | 499 | lcd.drawLine(51,28,51,38,1); |
| 200809780 | 0:f1120add03a8 | 500 | lcd.drawLine(54,26,54,40,1); |
| 200809780 | 0:f1120add03a8 | 501 | } |
| 200809780 | 0:f1120add03a8 | 502 | if (distance >= 200 && distance <300 ) { |
| 200809780 | 0:f1120add03a8 | 503 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 504 | lcd.drawLine(45,32,45,34,1); |
| 200809780 | 0:f1120add03a8 | 505 | lcd.drawLine(48,30,48,36,1); |
| 200809780 | 0:f1120add03a8 | 506 | lcd.drawLine(51,28,51,38,1); |
| 200809780 | 0:f1120add03a8 | 507 | } |
| 200809780 | 0:f1120add03a8 | 508 | if (distance >= 300 && distance <400 ) { |
| 200809780 | 0:f1120add03a8 | 509 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 510 | lcd.drawLine(45,32,45,34,1); |
| 200809780 | 0:f1120add03a8 | 511 | lcd.drawLine(48,30,48,36,1); |
| 200809780 | 0:f1120add03a8 | 512 | } |
| 200809780 | 0:f1120add03a8 | 513 | if (distance >= 400 && distance <=600 ) { |
| 200809780 | 0:f1120add03a8 | 514 | lcd.printString("***Move***",11,0); |
| 200809780 | 0:f1120add03a8 | 515 | lcd.drawLine(45,32,45,34,1); |
| 200809780 | 0:f1120add03a8 | 516 | } |
| 200809780 | 0:f1120add03a8 | 517 | if (distance > 600) { |
| 200809780 | 0:f1120add03a8 | 518 | lcd.printString("*Out of range*",0,0); |
| 200809780 | 0:f1120add03a8 | 519 | } |
| 200809780 | 0:f1120add03a8 | 520 | } |
| 200809780 | 0:f1120add03a8 | 521 | |
| 200809780 | 0:f1120add03a8 | 522 | void ButtonsOperation() |
| 200809780 | 0:f1120add03a8 | 523 | { |
| 200809780 | 0:f1120add03a8 | 524 | if (button3_flag == 0 && button4_flag==0) { // check the status of the button 3 and 4 |
| 200809780 | 0:f1120add03a8 | 525 | |
| 200809780 | 0:f1120add03a8 | 526 | buttonOperation_2(); // call function |
| 200809780 | 0:f1120add03a8 | 527 | } |
| 200809780 | 0:f1120add03a8 | 528 | |
| 200809780 | 0:f1120add03a8 | 529 | if (button3_flag == 1 && button4_flag==0) { // check the status of the button 3 and 4 |
| 200809780 | 0:f1120add03a8 | 530 | |
| 200809780 | 0:f1120add03a8 | 531 | lcd.clear();//clear display |
| 200809780 | 0:f1120add03a8 | 532 | lcd.refresh();//refresh display |
| 200809780 | 0:f1120add03a8 | 533 | buttonOperation_3(); // call function |
| 200809780 | 0:f1120add03a8 | 534 | button_4.rise(NULL); // button_4 becomes disable |
| 200809780 | 0:f1120add03a8 | 535 | button_2.rise(NULL); // button_2 becomes disable |
| 200809780 | 0:f1120add03a8 | 536 | } |
| 200809780 | 0:f1120add03a8 | 537 | |
| 200809780 | 0:f1120add03a8 | 538 | else |
| 200809780 | 0:f1120add03a8 | 539 | button_4.rise(&button4_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 540 | button_2.rise(&button2_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 541 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 542 | |
| 200809780 | 0:f1120add03a8 | 543 | if |
| 200809780 | 0:f1120add03a8 | 544 | (button4_flag == 1 && button3_flag==0 ) { |
| 200809780 | 0:f1120add03a8 | 545 | |
| 200809780 | 0:f1120add03a8 | 546 | lcd.clear(); |
| 200809780 | 0:f1120add03a8 | 547 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 548 | buttonOperation_4(); |
| 200809780 | 0:f1120add03a8 | 549 | button_3.rise(NULL); // button_3 becomes disable |
| 200809780 | 0:f1120add03a8 | 550 | button_2.rise(NULL); // button_2 becomes disable |
| 200809780 | 0:f1120add03a8 | 551 | |
| 200809780 | 0:f1120add03a8 | 552 | |
| 200809780 | 0:f1120add03a8 | 553 | } else |
| 200809780 | 0:f1120add03a8 | 554 | button_3.rise(&button3_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 555 | button_2.rise(&button2_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 556 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 557 | |
| 200809780 | 0:f1120add03a8 | 558 | } |
| 200809780 | 0:f1120add03a8 | 559 | |
| 200809780 | 0:f1120add03a8 | 560 | int main() |
| 200809780 | 0:f1120add03a8 | 561 | { |
| 200809780 | 0:f1120add03a8 | 562 | lcd.init();//initialise display |
| 200809780 | 0:f1120add03a8 | 563 | //set intial values of the leds |
| 200809780 | 0:f1120add03a8 | 564 | led_red = 0; |
| 200809780 | 0:f1120add03a8 | 565 | led_yellow=0; |
| 200809780 | 0:f1120add03a8 | 566 | led_green=0; |
| 200809780 | 0:f1120add03a8 | 567 | |
| 200809780 | 0:f1120add03a8 | 568 | int result = semihost_powerdown();// power down the USB interface |
| 200809780 | 0:f1120add03a8 | 569 | |
| 200809780 | 0:f1120add03a8 | 570 | timer_red.attach(&timerExpired_red, 0.2); // call ISR every 0.2 seconds |
| 200809780 | 0:f1120add03a8 | 571 | timer_yellow.attach(&timerExpired_yellow, 0.5); // call ISR every 0.5 seconds |
| 200809780 | 0:f1120add03a8 | 572 | timer_green.attach(&timerExpired_green, 0.8); // call ISR every 0.8 seconds |
| 200809780 | 0:f1120add03a8 | 573 | |
| 200809780 | 0:f1120add03a8 | 574 | button_1.rise(&button1_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 575 | button_2.rise(&button2_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 576 | button_3.rise(&button3_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 577 | button_4.rise(&button4_Pressed); // event generated on rising edge |
| 200809780 | 0:f1120add03a8 | 578 | |
| 200809780 | 0:f1120add03a8 | 579 | //set_time(1431299403); // initialise time to current time |
| 200809780 | 0:f1120add03a8 | 580 | |
| 200809780 | 0:f1120add03a8 | 581 | //print welcome messages |
| 200809780 | 0:f1120add03a8 | 582 | lcd.printString("Parking_Sensor",0,0);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 583 | lcd.printString("By",35,2);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 584 | lcd.printString("Andreas",20,3);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 585 | lcd.printString("Konstantinou",5,4);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 586 | |
| 200809780 | 0:f1120add03a8 | 587 | // draw lines and circles for the car on the right side of the display |
| 200809780 | 0:f1120add03a8 | 588 | lcd.drawLine(83,20,83,14,1); |
| 200809780 | 0:f1120add03a8 | 589 | lcd.drawLine(63,20,83,20,1); |
| 200809780 | 0:f1120add03a8 | 590 | lcd.drawLine(63,20,63,14,1); |
| 200809780 | 0:f1120add03a8 | 591 | lcd.drawLine(63,14,67,14,1); |
| 200809780 | 0:f1120add03a8 | 592 | lcd.drawLine(67,14,73,10,1); |
| 200809780 | 0:f1120add03a8 | 593 | lcd.drawLine(73,10,79,10,1); |
| 200809780 | 0:f1120add03a8 | 594 | lcd.drawLine(79,10,83,14,1); |
| 200809780 | 0:f1120add03a8 | 595 | lcd.drawCircle(67,20,2,1); |
| 200809780 | 0:f1120add03a8 | 596 | lcd.drawCircle(79,20,2,1); |
| 200809780 | 0:f1120add03a8 | 597 | // draw lines and circles for the car on the left side of the display |
| 200809780 | 0:f1120add03a8 | 598 | lcd.drawLine(20,20,20,14,1); |
| 200809780 | 0:f1120add03a8 | 599 | lcd.drawLine(0,20,20,20,1); |
| 200809780 | 0:f1120add03a8 | 600 | lcd.drawLine(0,20,0,14,1); |
| 200809780 | 0:f1120add03a8 | 601 | lcd.drawLine(0,14,4,14,1); |
| 200809780 | 0:f1120add03a8 | 602 | lcd.drawLine(4,14,10,10,1); |
| 200809780 | 0:f1120add03a8 | 603 | lcd.drawLine(10,10,16,10,1); |
| 200809780 | 0:f1120add03a8 | 604 | lcd.drawLine(16,10,20,14,1); |
| 200809780 | 0:f1120add03a8 | 605 | lcd.drawCircle(4,20,2,1); |
| 200809780 | 0:f1120add03a8 | 606 | lcd.drawCircle(16,20,2,1); |
| 200809780 | 0:f1120add03a8 | 607 | |
| 200809780 | 0:f1120add03a8 | 608 | //draw lines for the road |
| 200809780 | 0:f1120add03a8 | 609 | lcd.drawLine(0,41,83,41,1); |
| 200809780 | 0:f1120add03a8 | 610 | lcd.drawLine(0,44,83,44,2); |
| 200809780 | 0:f1120add03a8 | 611 | lcd.drawLine(0,47,83,47,1); |
| 200809780 | 0:f1120add03a8 | 612 | |
| 200809780 | 0:f1120add03a8 | 613 | wait(2.5);// 2.5 seconds delay |
| 200809780 | 0:f1120add03a8 | 614 | lcd.clear();//clear the screen |
| 200809780 | 0:f1120add03a8 | 615 | lcd.refresh();//refresh the display |
| 200809780 | 0:f1120add03a8 | 616 | |
| 200809780 | 0:f1120add03a8 | 617 | for (int j= 0; j>-83; j--) { |
| 200809780 | 0:f1120add03a8 | 618 | lcd.printString("*University*",5,0);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 619 | lcd.printString("**Of Leeds**",5,1);//display on the N5110 LCD |
| 200809780 | 0:f1120add03a8 | 620 | //draw lines for the road on the screen |
| 200809780 | 0:f1120add03a8 | 621 | lcd.drawLine(0,30,83,30,1); |
| 200809780 | 0:f1120add03a8 | 622 | lcd.drawLine(0,32,83,32,2); |
| 200809780 | 0:f1120add03a8 | 623 | lcd.drawLine(0,35,83,35,1); |
| 200809780 | 0:f1120add03a8 | 624 | |
| 200809780 | 0:f1120add03a8 | 625 | // draw lines and circles for the cars on the display |
| 200809780 | 0:f1120add03a8 | 626 | lcd.drawLine(83+j,30,83+j,24,1); |
| 200809780 | 0:f1120add03a8 | 627 | lcd.drawLine(63+j,30,83+j,30,1); |
| 200809780 | 0:f1120add03a8 | 628 | lcd.drawLine(63+j,30,63+j,24,1); |
| 200809780 | 0:f1120add03a8 | 629 | lcd.drawLine(63+j,24,67+j,24,1); |
| 200809780 | 0:f1120add03a8 | 630 | lcd.drawLine(67+j,24,73+j,20,1); |
| 200809780 | 0:f1120add03a8 | 631 | lcd.drawLine(73+j,20,79+j,20,1); |
| 200809780 | 0:f1120add03a8 | 632 | lcd.drawLine(79+j,20,83+j,24,1); |
| 200809780 | 0:f1120add03a8 | 633 | lcd.drawCircle(67+j,30,2,1); |
| 200809780 | 0:f1120add03a8 | 634 | lcd.drawCircle(79+j,30,2,1); |
| 200809780 | 0:f1120add03a8 | 635 | |
| 200809780 | 0:f1120add03a8 | 636 | lcd.drawLine(53+j,30,53+j,24,1); |
| 200809780 | 0:f1120add03a8 | 637 | lcd.drawLine(33+j,30,53+j,30,1); |
| 200809780 | 0:f1120add03a8 | 638 | lcd.drawLine(33+j,30,33+j,24,1); |
| 200809780 | 0:f1120add03a8 | 639 | lcd.drawLine(33+j,24,37+j,24,1); |
| 200809780 | 0:f1120add03a8 | 640 | lcd.drawLine(37+j,24,43+j,20,1); |
| 200809780 | 0:f1120add03a8 | 641 | lcd.drawLine(43+j,20,49+j,20,1); |
| 200809780 | 0:f1120add03a8 | 642 | lcd.drawLine(49+j,20,53+j,24,1); |
| 200809780 | 0:f1120add03a8 | 643 | lcd.drawCircle(37+j,30,2,1); |
| 200809780 | 0:f1120add03a8 | 644 | lcd.drawCircle(49+j,30,2,1); |
| 200809780 | 0:f1120add03a8 | 645 | |
| 200809780 | 0:f1120add03a8 | 646 | wait(0.10);//small delay |
| 200809780 | 0:f1120add03a8 | 647 | lcd.clear(); |
| 200809780 | 0:f1120add03a8 | 648 | lcd.refresh(); |
| 200809780 | 0:f1120add03a8 | 649 | } |
| 200809780 | 0:f1120add03a8 | 650 | |
| 200809780 | 0:f1120add03a8 | 651 | while(1) {// infinite loop |
| 200809780 | 0:f1120add03a8 | 652 | |
| 200809780 | 0:f1120add03a8 | 653 | |
| 200809780 | 0:f1120add03a8 | 654 | a1=ain1.read(); // read the value of potentiometer |
| 200809780 | 0:f1120add03a8 | 655 | lcd.setBrightness(a1);// function to change LED backlight brightness using the potentiometer |
| 200809780 | 0:f1120add03a8 | 656 | |
| 200809780 | 0:f1120add03a8 | 657 | //call the functions |
| 200809780 | 0:f1120add03a8 | 658 | Get_Average(); |
| 200809780 | 0:f1120add03a8 | 659 | ButtonsOperation(); |
| 200809780 | 0:f1120add03a8 | 660 | buttonOperation_1(); |
| 200809780 | 0:f1120add03a8 | 661 | |
| 200809780 | 0:f1120add03a8 | 662 | Sleep(); |
| 200809780 | 0:f1120add03a8 | 663 | } |
| 200809780 | 0:f1120add03a8 | 664 | } |