This is the final project involving a parking distance guider and radar distance sensor, with an additional setting option involved. It was made by Nestor Isaac Garcia Rueda (SID: 200798965) and e-mail address: nestorgarciarueda@hotmail.com

Dependencies:   N5110 PowerControl SRF02 beep mbed

Committer:
NestorLDS
Date:
Mon May 11 21:57:55 2015 +0000
Revision:
0:356be0c38cf1
When Finished

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NestorLDS 0:356be0c38cf1 1 /**
NestorLDS 0:356be0c38cf1 2 @file Button.cpp
NestorLDS 0:356be0c38cf1 3 @brief main file for the Ultrasound Distance Sensor Project.
NestorLDS 0:356be0c38cf1 4 @brief Has three main functions; parking distance guide, ultrasound radar and settings.
NestorLDS 0:356be0c38cf1 5 @brief Revision 3.6.
NestorLDS 0:356be0c38cf1 6 @author Nestor Isaac Garcia Rueda (200798965)
NestorLDS 0:356be0c38cf1 7 @date 02/May/2015
NestorLDS 0:356be0c38cf1 8 */
NestorLDS 0:356be0c38cf1 9
NestorLDS 0:356be0c38cf1 10 /*Here, we are including the following libraries and its respectively codes*/
NestorLDS 0:356be0c38cf1 11 #include "mbed.h" /*Importing the mbed.h library header file of the mbed NXP LPC 1768 Microcontroller*/
NestorLDS 0:356be0c38cf1 12 #include "N5110.h" /*Importing the N5110.h library header file of the Nokia 5110 LCD screen*/
NestorLDS 0:356be0c38cf1 13 #include "SRF02.h" /*Importing the SRF02.h library header file of the SRF02 ultrasound device*/
NestorLDS 0:356be0c38cf1 14 #include "beep.h" /*Importing beep.h library header file of the beep library*/
NestorLDS 0:356be0c38cf1 15 #include "PowerControl/PowerControl.h" /*Importing the PowerControl/PowerControl.h library header file of the PowerControl library*/
NestorLDS 0:356be0c38cf1 16 #include "PowerControl/EthernetPowerControl.h" /*Importing the PowerControl/EthernetPowerControl.h library header file of the PowerControl library*/
NestorLDS 0:356be0c38cf1 17
NestorLDS 0:356be0c38cf1 18 AnalogIn pot(p20); /*Declaring name space (pot) and pin number (p20) of the potentiometer*/
NestorLDS 0:356be0c38cf1 19 Beep buzzer(p21); /*Declaring name space (buzzer) and pin number (p21) of the buzzer speaker*/
NestorLDS 0:356be0c38cf1 20 InterruptIn button(p18); /*Declaring name space (button) and pin number (p18) of the interrupt button*/
NestorLDS 0:356be0c38cf1 21 BusOut inLeds(LED3,LED4); /*Declaring name space (inLeds) and inner embedded LEDs of mbed NXP LPC 1768 Microcontroller*/
NestorLDS 0:356be0c38cf1 22
NestorLDS 0:356be0c38cf1 23 //Serial serial(USBTX,USBRX); /*Declaration of serial interface for CoolTerm debugging with usb transmitter and receiver defintitions*/
NestorLDS 0:356be0c38cf1 24
NestorLDS 0:356be0c38cf1 25 BusOut pcbLEDS (p25,p24,p23,p22); /*Declaring name space (pcbLEDS) and its corresponding pin numbers (p25,p24,p23,p22) of the LEDs of the PCB*/
NestorLDS 0:356be0c38cf1 26 N5110 lcd(p7,p8,p9,p10,p11,p13,p26); /*Declaring name space (lcd) and corresponding pin numbers (p7,p8,p9,p10,p11,p13,p26) of the Nokia 5110 LCD screen*/
NestorLDS 0:356be0c38cf1 27 SRF02 srf02(p28,p27); /*Declaring SDA and SCL pins (p28,p27)*/
NestorLDS 0:356be0c38cf1 28
NestorLDS 0:356be0c38cf1 29 Ticker onBoardLedTimer; /*Ticker object for blinking on board LED*/
NestorLDS 0:356be0c38cf1 30 Ticker refLed; /*Ticker object to eliminate the need for wait() function for the on-PCB status LED's*/
NestorLDS 0:356be0c38cf1 31 Ticker clearTimer;
NestorLDS 0:356be0c38cf1 32
NestorLDS 0:356be0c38cf1 33 int c = 1; /*Float is 0.something and 'int' represents whole numbers, where we are declaring 'c' to be a whole number and to have a value of 1*/
NestorLDS 0:356be0c38cf1 34 void ledFlow() /*Void function for executing the brightness backlight pre-intro presentation*/
NestorLDS 0:356be0c38cf1 35 {
NestorLDS 0:356be0c38cf1 36 pcbLEDS = 8; /*The named space previously defined, lights on, in this case 2^3= 8 in binary, therefore it only will the fourth led*/
NestorLDS 0:356be0c38cf1 37 wait_ms(200); /*Waiting time delay of 0.2 seconds*/
NestorLDS 0:356be0c38cf1 38 pcbLEDS = 12; /*Lights on, in this case 2^3+2^2= 12 in binary, therefore it will only the third and fourth led*/
NestorLDS 0:356be0c38cf1 39 wait_ms(200); /*Delay of 0.2 seconds*/
NestorLDS 0:356be0c38cf1 40 pcbLEDS = 14; /*Lights on, in this case 2^3+2^2+2^1= 14 in binary, therefore it will only the second, third and fourth led*/
NestorLDS 0:356be0c38cf1 41 wait_ms(200); /*Delay of 0.2 seconds*/
NestorLDS 0:356be0c38cf1 42 pcbLEDS = 15; /*Lights on, in this case 2^3+2^2+2^1+2^0= 15 in binary, therefore it will all the four leds*/
NestorLDS 0:356be0c38cf1 43 wait_ms(200); /*Delay of 0.2 seconds*/
NestorLDS 0:356be0c38cf1 44 pcbLEDS = 0; /*Lights off all leds*/
NestorLDS 0:356be0c38cf1 45
NestorLDS 0:356be0c38cf1 46 }
NestorLDS 0:356be0c38cf1 47
NestorLDS 0:356be0c38cf1 48 float d = 1; /* Float is 0.smth and int whole*/
NestorLDS 0:356be0c38cf1 49 void ledLaserA() /* Void function named ledLaserA for executing the code below to be able to be called and run, executing the different led states*/
NestorLDS 0:356be0c38cf1 50 {
NestorLDS 0:356be0c38cf1 51 pcbLEDS = 1; /*The named space previously defined, lights on, in this case 2^0= 1 in binary, therefore it only will the first led*/
NestorLDS 0:356be0c38cf1 52 wait_ms(110); /*Delay of 0.11 seconds*/
NestorLDS 0:356be0c38cf1 53 pcbLEDS = 3;; /*Lights on, in this case 2^1+2^0= 3 in binary, therefore it only will the first and second leds*/
NestorLDS 0:356be0c38cf1 54 wait_ms(90); /*Delay of 0.09 seconds*/
NestorLDS 0:356be0c38cf1 55 pcbLEDS = 7;; /*Lights on, in this case 2^2+2^1+2^0= 7 in binary, therefore it only will the first, second and third leds*/
NestorLDS 0:356be0c38cf1 56 wait_ms(90); /*Delay of 0.09 seconds*/
NestorLDS 0:356be0c38cf1 57 pcbLEDS = 15; /*Lights on, in this case 2^3+2^2+2^1+2^0= 15 in binary, therefore it will then the first, second, third and fourth leds*/
NestorLDS 0:356be0c38cf1 58 wait_ms(90); /*Delay of 0.09 seconds*/
NestorLDS 0:356be0c38cf1 59 }
NestorLDS 0:356be0c38cf1 60 void ledLaserB() /*void function for ledLaserB led flashing states*/
NestorLDS 0:356be0c38cf1 61 {
NestorLDS 0:356be0c38cf1 62 pcbLEDS = 8; /*The named space previously defined, lights on, in this case 2^3= 8 in binary, therefore it only will the fourth led*/
NestorLDS 0:356be0c38cf1 63 wait_ms(110); /*Delay of 0.11 seconds*/
NestorLDS 0:356be0c38cf1 64 pcbLEDS = 12; /*Lights on, in this case 2^3+2^2= 12 in binary, therefore it will only the third and fourth led*/
NestorLDS 0:356be0c38cf1 65 wait_ms(90); /*Delay of 0.09 seconds*/
NestorLDS 0:356be0c38cf1 66 pcbLEDS = 14; /*Lights on, in this case 2^3+2^2+2^1= 14 in binary, therefore it will only the second, third and fourth led*/
NestorLDS 0:356be0c38cf1 67 wait_ms(90); /*Delay of 0.09 seconds*/
NestorLDS 0:356be0c38cf1 68 pcbLEDS = 15; /*Lights on, in this case 2^3+2^2+2^1+2^0= 15 in binary, therefore it will all the four leds*/
NestorLDS 0:356be0c38cf1 69 wait_ms(90); /*Delay of 0.09 seconds*/
NestorLDS 0:356be0c38cf1 70 pcbLEDS = 0; /*Lights off all leds*/
NestorLDS 0:356be0c38cf1 71 }
NestorLDS 0:356be0c38cf1 72
NestorLDS 0:356be0c38cf1 73 int buttonFlag = 0; /*between variable = 0 and variableReading = 0.3*/
NestorLDS 0:356be0c38cf1 74 int buttonAltFlag = 0; /*Alternate flag between variable = 0.3 and variableReading = 0.6*/
NestorLDS 0:356be0c38cf1 75 int buttonSecondAltFlag = 0; /*Second Alternate flag beyond variable = 0*/
NestorLDS 0:356be0c38cf1 76
NestorLDS 0:356be0c38cf1 77 float variableReading = pot.read(); /*fetches potentiometer reading between 0 and 1 and stores it in a variable, potReading*/
NestorLDS 0:356be0c38cf1 78
NestorLDS 0:356be0c38cf1 79 void action() //Interrupt Service Routine for Button
NestorLDS 0:356be0c38cf1 80 {
NestorLDS 0:356be0c38cf1 81 if(variableReading <= 0.3) { //less than this pot ratio
NestorLDS 0:356be0c38cf1 82 buttonFlag = !buttonFlag; //if flag = 0 set it to 1; otherwise reset it to 0.
NestorLDS 0:356be0c38cf1 83 }
NestorLDS 0:356be0c38cf1 84
NestorLDS 0:356be0c38cf1 85 else if(variableReading > 0.3 & variableReading < 0.6) { //if otherwise pot reading between this pot ratio range - radar
NestorLDS 0:356be0c38cf1 86 buttonAltFlag = !buttonAltFlag; //if flag = 0 set it to 1; otherwise reset it to 0.
NestorLDS 0:356be0c38cf1 87 }
NestorLDS 0:356be0c38cf1 88
NestorLDS 0:356be0c38cf1 89 else if(variableReading >= 0.6) { //or else this pot ratio is exceeded
NestorLDS 0:356be0c38cf1 90 //lcd.setBrightness(pot.read());
NestorLDS 0:356be0c38cf1 91 buttonSecondAltFlag = !buttonSecondAltFlag;
NestorLDS 0:356be0c38cf1 92 // lcd.setBrightness(pot.read());
NestorLDS 0:356be0c38cf1 93
NestorLDS 0:356be0c38cf1 94 }
NestorLDS 0:356be0c38cf1 95
NestorLDS 0:356be0c38cf1 96 if ( variableReading < 0.6 && buttonSecondAltFlag == 1) {
NestorLDS 0:356be0c38cf1 97 buttonSecondAltFlag = !buttonSecondAltFlag;
NestorLDS 0:356be0c38cf1 98 // lcd.setBrightness(pot.read());
NestorLDS 0:356be0c38cf1 99 }
NestorLDS 0:356be0c38cf1 100
NestorLDS 0:356be0c38cf1 101 }
NestorLDS 0:356be0c38cf1 102
NestorLDS 0:356be0c38cf1 103 int LedFlag = 0; //flag set to change on-board LED state
NestorLDS 0:356be0c38cf1 104
NestorLDS 0:356be0c38cf1 105 void LedTimerSet() //Interrupt Service Routine for LedTimer
NestorLDS 0:356be0c38cf1 106 {
NestorLDS 0:356be0c38cf1 107 LedFlag = 1; //set flag when timer expires.
NestorLDS 0:356be0c38cf1 108 }
NestorLDS 0:356be0c38cf1 109
NestorLDS 0:356be0c38cf1 110 int refLedFlag = 0;
NestorLDS 0:356be0c38cf1 111
NestorLDS 0:356be0c38cf1 112 void refLedFlipped()
NestorLDS 0:356be0c38cf1 113 {
NestorLDS 0:356be0c38cf1 114 refLedFlag = 1;
NestorLDS 0:356be0c38cf1 115 }
NestorLDS 0:356be0c38cf1 116
NestorLDS 0:356be0c38cf1 117 int clearFlag = 0;
NestorLDS 0:356be0c38cf1 118
NestorLDS 0:356be0c38cf1 119 void clearTimeout()
NestorLDS 0:356be0c38cf1 120 {
NestorLDS 0:356be0c38cf1 121 clearFlag = 1;
NestorLDS 0:356be0c38cf1 122 }
NestorLDS 0:356be0c38cf1 123
NestorLDS 0:356be0c38cf1 124 bool state;
NestorLDS 0:356be0c38cf1 125
NestorLDS 0:356be0c38cf1 126 float a= 0.0; /*Floating data integer type constant defined as "a" and given the value of 0.0*/
NestorLDS 0:356be0c38cf1 127 int counter = 0; /*Integer r set as an integer of 0*/
NestorLDS 0:356be0c38cf1 128 void increaseBrightness() /*void function for executing the brightness backlight pre-intro presentation*/
NestorLDS 0:356be0c38cf1 129 {
NestorLDS 0:356be0c38cf1 130 a+=0.2; /*increases by 0.2 the 'a' constant*/
NestorLDS 0:356be0c38cf1 131 lcd.setBrightness(a); /*the lcd brightness is been set, with the pre-set and defined constant ''a'', as the initial value state*/
NestorLDS 0:356be0c38cf1 132 wait_ms(150); /*Delay of 0.15 seconds*/
NestorLDS 0:356be0c38cf1 133 }
NestorLDS 0:356be0c38cf1 134
NestorLDS 0:356be0c38cf1 135 void preIntro () /*void function for preIntro that performs the counting, increment and reset of the constant "a" state depending on its floating value, taking into account the task of counting floating numbers*/
NestorLDS 0:356be0c38cf1 136 {
NestorLDS 0:356be0c38cf1 137
NestorLDS 0:356be0c38cf1 138 while(counter < 2) { /*A while loop that when the counter reaches 2, stops executing*/
NestorLDS 0:356be0c38cf1 139
NestorLDS 0:356be0c38cf1 140
NestorLDS 0:356be0c38cf1 141 increaseBrightness(); /*calls the function*/
NestorLDS 0:356be0c38cf1 142 if (a>0.4 && a<0.7) {
NestorLDS 0:356be0c38cf1 143 lcd.inverseMode(); /*White and black pixels get inversed*/
NestorLDS 0:356be0c38cf1 144 }
NestorLDS 0:356be0c38cf1 145
NestorLDS 0:356be0c38cf1 146 else if (a>=1) { /*so i} the constant 'a' gets higher or equal to 1, after increasing by 0.2 every time, will execute the code line below*/
NestorLDS 0:356be0c38cf1 147 a = 0;
NestorLDS 0:356be0c38cf1 148 counter++; /*sets the constant 'a' value to 0 and adds 1 to the counter when the if statement is met*/
NestorLDS 0:356be0c38cf1 149
NestorLDS 0:356be0c38cf1 150 } else { /*Else statement*/
NestorLDS 0:356be0c38cf1 151 lcd.normalMode(); /*Calls the member function normal mode running the code*/
NestorLDS 0:356be0c38cf1 152 }
NestorLDS 0:356be0c38cf1 153 }
NestorLDS 0:356be0c38cf1 154 }
NestorLDS 0:356be0c38cf1 155
NestorLDS 0:356be0c38cf1 156 void superIntro()
NestorLDS 0:356be0c38cf1 157 {
NestorLDS 0:356be0c38cf1 158
NestorLDS 0:356be0c38cf1 159 //LCD DISPLAY
NestorLDS 0:356be0c38cf1 160
NestorLDS 0:356be0c38cf1 161 ledFlow(); /*calls the ledFlow function been declared above*/
NestorLDS 0:356be0c38cf1 162 lcd.clear(); /*Clears screen by running the member function clear of the class lcd*/
NestorLDS 0:356be0c38cf1 163 lcd.refresh(); /*Refreshes screen by runnig member function*/
NestorLDS 0:356be0c38cf1 164 pcbLEDS = 0; /*Lights off all leds*/
NestorLDS 0:356be0c38cf1 165 lcd.printString("Electronic",15,0); /*Calls the member function printString running the code and allowing us to print what's between quotation marks and the coordinates Y,X axis of 15 and 0*/
NestorLDS 0:356be0c38cf1 166 lcd.printString("&",40,1); /*Prints on the lcd screen only the symbol "&" between quotation marks on the 40,1 Y,X axis coordinates*/
NestorLDS 0:356be0c38cf1 167 lcd.printString("Electrical",6,2); /*Prints "Electrical" on the 6,2 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 168 lcd.printString("Engineer",37,3); /*Prints "Engineer" on the 37,3 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 169 lcd.printString("PRESENTS",5,4); /*Prints "PRESENTS" on the 5,4 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 170 lcd.printString("///*///*///*//",0,5); /*Prints "///*///*///*//" on the 0,5 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 171 wait(2); /*Delay of 2 secs*/
NestorLDS 0:356be0c38cf1 172
NestorLDS 0:356be0c38cf1 173
NestorLDS 0:356be0c38cf1 174 ledFlow(); /*calls the ledFlow function been declared above*/
NestorLDS 0:356be0c38cf1 175 lcd.clear(); /*Clears screen by running the member function clear of the class lcd*/
NestorLDS 0:356be0c38cf1 176 lcd.printString("///*///*///*//",0,0); /*Prints "///*///*///*//" on the 0,0 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 177 lcd.printString("The",34,1); /*Prints "The" on the 34,1 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 178 lcd.printString("SRF",34,2); /*Prints "SRF" on the 34,2 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 179 lcd.printString("Ultrasound",13,3); /*Prints "Ultrasound" on the 13,3 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 180 lcd.printString("Project",21,4); /*Prints "Project" on the 21,4 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 181 lcd.printString("///*///*///*//",0,5); /*Prints "///*///*///*//" on the 0,5 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 182 lcd.inverseMode(); /*calls the function from the N5110.h library and runs the function inverseMode to inverse the B&W pixel states*/
NestorLDS 0:356be0c38cf1 183 wait(2); /*waiting time of 2secs*/
NestorLDS 0:356be0c38cf1 184
NestorLDS 0:356be0c38cf1 185 ledFlow(); /*calls the ledFlow function been declared above*/
NestorLDS 0:356be0c38cf1 186 lcd.clear(); /*clears screen*/
NestorLDS 0:356be0c38cf1 187 lcd.printString("///*///*///*//",0,0); /*Prints "///*///*///*//" on the 0,0 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 188 lcd.printString("Designed",15,1); /*Prints "Designed" on the 15,1 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 189 lcd.printString("By",34,2); /*Prints "By" on the 34,2 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 190 lcd.printString("Nestor Isaac",7,3); /*Prints "Nestor Isaac" on the 7,3 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 191 lcd.printString("Garcia Rueda",7,4); /*Prints "Garcia Rueda" on the 7,4 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 192 lcd.printString("///*///*///*//",0,5); /*Prints "///*///*///*//" on the 0,5 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 193 lcd.normalMode(); /*calls the function from the N5110.h library and runs the function normalMode to normal the B&W pixel states*/
NestorLDS 0:356be0c38cf1 194 wait(3); /*waiting time of 3secs*/
NestorLDS 0:356be0c38cf1 195 pcbLEDS=15; /*Lights on, in this case 2^3+2^2+2^1+2^0= 15 in binary, therefore it will all the four leds*/
NestorLDS 0:356be0c38cf1 196 lcd.refresh(); /*refreshes screen by running the corresponding member function*/
NestorLDS 0:356be0c38cf1 197 lcd.clear(); /*clears screen by running the corresponding member function inside the lcd class*/
NestorLDS 0:356be0c38cf1 198 }
NestorLDS 0:356be0c38cf1 199
NestorLDS 0:356be0c38cf1 200 int main () /*Starts the main function where "int" represents the data type of the return value from the pgoramme where if returned a 0, means that its worked ok and if returned 1, would mean that something went wrong*/
NestorLDS 0:356be0c38cf1 201 { /*Curly bracket that reresets the openning/begining of the main function*/
NestorLDS 0:356be0c38cf1 202 PHY_PowerDown(); /*Ethernet Power-Down, saves up around 175mW*/
NestorLDS 0:356be0c38cf1 203 lcd.init(); /*Initialises screen by running the member function init of the class lcd*/
NestorLDS 0:356be0c38cf1 204 preIntro(); /*Calls the defined void function "preIntro" declared above*/
NestorLDS 0:356be0c38cf1 205 superIntro(); /*Calls the defined void function "preIntro" declared above*/
NestorLDS 0:356be0c38cf1 206 button.rise(&action);
NestorLDS 0:356be0c38cf1 207
NestorLDS 0:356be0c38cf1 208 onBoardLedTimer.attach(&LedTimerSet,1.0); /*call ISR every second second*/
NestorLDS 0:356be0c38cf1 209
NestorLDS 0:356be0c38cf1 210 refLed.attach(&refLedFlipped,0.3); /*call ISR once after 0.3 seconds elapse*/
NestorLDS 0:356be0c38cf1 211
NestorLDS 0:356be0c38cf1 212 clearTimer.attach(&clearTimeout,0.25); /* calls ISR every quarter of a second*/
NestorLDS 0:356be0c38cf1 213
NestorLDS 0:356be0c38cf1 214 while(1) { /*Initialises a while loop that loops reading code forever*/
NestorLDS 0:356be0c38cf1 215
NestorLDS 0:356be0c38cf1 216 if(clearFlag) { /*If statement that only executing if the clearFlag statement is met and runs the inner statement of "if"*/
NestorLDS 0:356be0c38cf1 217
NestorLDS 0:356be0c38cf1 218 lcd.clear(); /*clears screen by running the corresponding member function inside the lcd class*/
NestorLDS 0:356be0c38cf1 219 clearFlag = 0; /*Makes the clearFlag value to be set initially as 0*/
NestorLDS 0:356be0c38cf1 220 variableReading = pot.read(); /*Here, we are just saying that the declared floating declaration variableReading is equals to pot.read(), which reads the potentiometer resistance*/
NestorLDS 0:356be0c38cf1 221 /*serial.printf("variable reading is %d\n",state);*/ /*This code was additionally used as for debugging purposes using CoolTerm so we could print ht ereadings when connecting our mbed platform to the programme*/
NestorLDS 0:356be0c38cf1 222 lcd.drawRect(15,5,60,10,0); /* filled black rectangle Y,X,length, width,1=FILLIN/0=NON-FILLING*/
NestorLDS 0:356be0c38cf1 223 lcd.drawRect(15,20,60,10,0); /* filled black rectangle Y,X,length, width,1=FILLIN/0=NON-FILLING*/
NestorLDS 0:356be0c38cf1 224 lcd.drawRect(15,35,60,10,0); /* filled black rectangle Y,X,length, width,1=FILLIN/0=NON-FILLING*/
NestorLDS 0:356be0c38cf1 225
NestorLDS 0:356be0c38cf1 226 lcd.drawCircle(WIDTH/11,HEIGHT/5.2,5,0); /*Here, it takes the declared WIDTH on the lcd library of 84 pixels(in this case divided by 11) on the x axis and HEIGHT of 48 pixels in the y axis (in this case divided by 5.2),with a radius of 5cm,and 0 fo an white empty circle and 1 for a black filled circle that prints on the lcd screen*/
NestorLDS 0:356be0c38cf1 227 lcd.drawCircle(WIDTH/11,HEIGHT/1.97,5,0); /*It calls the member function "drawCircle" inside the lcd class, with a WIDTH of 84/11, a HEIGHT of 48/1.97, a radius of 5, and a empty filled circle (0)*/
NestorLDS 0:356be0c38cf1 228 lcd.drawCircle(WIDTH/11,HEIGHT/1.2,5,0); /*It calls the member function "drawCircle" inside the lcd class, with a WIDTH of 84/11, a HEIGHT of 48/1.2, a radius of 5, and a empty filled circle (0)*/
NestorLDS 0:356be0c38cf1 229
NestorLDS 0:356be0c38cf1 230 lcd.printString("PARKING",23,1); /*Prints "Electrical" on the 6,2 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 231 lcd.printString("RADAR",29,3); /*Prints "Electrical" on the 6,2 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 232 lcd.printString("SETTINGS",20,5); /*Prints "Electrical" on the 6,2 X,Y axis coordinates of the LCD*/
NestorLDS 0:356be0c38cf1 233
NestorLDS 0:356be0c38cf1 234
NestorLDS 0:356be0c38cf1 235
NestorLDS 0:356be0c38cf1 236 if (variableReading <= 0.3) { /*This is for the PARKING option*/
NestorLDS 0:356be0c38cf1 237 lcd.drawCircle(WIDTH/11,HEIGHT/5.2,5,1); // x,y,radius,black fill
NestorLDS 0:356be0c38cf1 238 ledLaserA();
NestorLDS 0:356be0c38cf1 239 lcd.refresh();
NestorLDS 0:356be0c38cf1 240 ledLaserB();
NestorLDS 0:356be0c38cf1 241 lcd.drawCircle(WIDTH/11,HEIGHT/5.2,5,1); // x,y,radius,black fill
NestorLDS 0:356be0c38cf1 242 lcd.refresh();
NestorLDS 0:356be0c38cf1 243
NestorLDS 0:356be0c38cf1 244 while(buttonFlag == 1) {
NestorLDS 0:356be0c38cf1 245 lcd.clear();
NestorLDS 0:356be0c38cf1 246 //buzzer.beep(200,1.5);
NestorLDS 0:356be0c38cf1 247 inLeds = 1;
NestorLDS 0:356be0c38cf1 248 if(LedFlag) { //if flag has been set
NestorLDS 0:356be0c38cf1 249 inLeds = inLeds + 1;
NestorLDS 0:356be0c38cf1 250 if(inLeds < 3) {
NestorLDS 0:356be0c38cf1 251 inLeds = 0;
NestorLDS 0:356be0c38cf1 252 }
NestorLDS 0:356be0c38cf1 253 LedFlag = 0; //reset flag
NestorLDS 0:356be0c38cf1 254 }
NestorLDS 0:356be0c38cf1 255 int distReading = srf02.getDistanceCm();
NestorLDS 0:356be0c38cf1 256
NestorLDS 0:356be0c38cf1 257 lcd.clear();
NestorLDS 0:356be0c38cf1 258
NestorLDS 0:356be0c38cf1 259 char stringBuffer[14];
NestorLDS 0:356be0c38cf1 260
NestorLDS 0:356be0c38cf1 261 lcd.printString("Measured range",0,2);
NestorLDS 0:356be0c38cf1 262
NestorLDS 0:356be0c38cf1 263 sprintf(stringBuffer,":%dcm",distReading);
NestorLDS 0:356be0c38cf1 264
NestorLDS 0:356be0c38cf1 265 lcd.printString(stringBuffer,43,3);
NestorLDS 0:356be0c38cf1 266 lcd.refresh();
NestorLDS 0:356be0c38cf1 267
NestorLDS 0:356be0c38cf1 268 if (distReading >=12 && distReading <=15 ) {
NestorLDS 0:356be0c38cf1 269 pcbLEDS = 8;
NestorLDS 0:356be0c38cf1 270 lcd.printString("///*///*///*//",0,0); //Y,X axis
NestorLDS 0:356be0c38cf1 271 lcd.printString("WELL DONE!",0,1);
NestorLDS 0:356be0c38cf1 272 lcd.printString("car parked at ",0,2);
NestorLDS 0:356be0c38cf1 273 lcd.printString("///*///*///*//",0,4); //Y,X axis
NestorLDS 0:356be0c38cf1 274 lcd.printString("///*///*///*//",0,5); //Y,X axis
NestorLDS 0:356be0c38cf1 275 buzzer.beep(200,1.5);
NestorLDS 0:356be0c38cf1 276 wait(4);
NestorLDS 0:356be0c38cf1 277 }
NestorLDS 0:356be0c38cf1 278 if (distReading > 15 && distReading <= 30) {
NestorLDS 0:356be0c38cf1 279 pcbLEDS = 12;
NestorLDS 0:356be0c38cf1 280 lcd.printString("//////////////",0,0); //Y,X axis
NestorLDS 0:356be0c38cf1 281 lcd.printString("wall at",0,3);
NestorLDS 0:356be0c38cf1 282 lcd.printString("Slow approach,",0,2);
NestorLDS 0:356be0c38cf1 283 // lcd.printString("recommended",0,4);
NestorLDS 0:356be0c38cf1 284
NestorLDS 0:356be0c38cf1 285 wait_ms(300);
NestorLDS 0:356be0c38cf1 286 }
NestorLDS 0:356be0c38cf1 287 if (distReading > 30 && distReading <= 50) {
NestorLDS 0:356be0c38cf1 288 pcbLEDS = 14;
NestorLDS 0:356be0c38cf1 289 wait_ms(300);
NestorLDS 0:356be0c38cf1 290 }
NestorLDS 0:356be0c38cf1 291 if (distReading > 50 && distReading <= 50) {
NestorLDS 0:356be0c38cf1 292 pcbLEDS = 15;
NestorLDS 0:356be0c38cf1 293 wait_ms(300);
NestorLDS 0:356be0c38cf1 294 } else {
NestorLDS 0:356be0c38cf1 295 //pcbLEDS = 15;
NestorLDS 0:356be0c38cf1 296 // wait_ms(300);
NestorLDS 0:356be0c38cf1 297 // pcbLEDS = 0;
NestorLDS 0:356be0c38cf1 298 ledFlow();
NestorLDS 0:356be0c38cf1 299 lcd.refresh();
NestorLDS 0:356be0c38cf1 300 }
NestorLDS 0:356be0c38cf1 301 lcd.refresh();
NestorLDS 0:356be0c38cf1 302
NestorLDS 0:356be0c38cf1 303 // if (distReading < 35) {
NestorLDS 0:356be0c38cf1 304 // buzzer.beep(500,1.0);
NestorLDS 0:356be0c38cf1 305 // pcbLEDS = 14;
NestorLDS 0:356be0c38cf1 306 // wait_ms(300);
NestorLDS 0:356be0c38cf1 307 //
NestorLDS 0:356be0c38cf1 308 // if (distReading < 25) {
NestorLDS 0:356be0c38cf1 309 // buzzer.beep(1000,1.0);
NestorLDS 0:356be0c38cf1 310 // pcbLEDS = 12;
NestorLDS 0:356be0c38cf1 311 // wait_ms(300);
NestorLDS 0:356be0c38cf1 312 //
NestorLDS 0:356be0c38cf1 313 // if (distReading < 15) {
NestorLDS 0:356be0c38cf1 314 // buzzer.beep(9000,1.0);
NestorLDS 0:356be0c38cf1 315 // pcbLEDS = 8;
NestorLDS 0:356be0c38cf1 316 // wait_ms(300);
NestorLDS 0:356be0c38cf1 317 // } //close dist reading 15
NestorLDS 0:356be0c38cf1 318 // lcd.refresh();
NestorLDS 0:356be0c38cf1 319 // } //close dist reading 35
NestorLDS 0:356be0c38cf1 320 // } //close button flag 1
NestorLDS 0:356be0c38cf1 321 // } //close variable reading 0.3 to 0.6
NestorLDS 0:356be0c38cf1 322 lcd.refresh();
NestorLDS 0:356be0c38cf1 323 }
NestorLDS 0:356be0c38cf1 324 lcd.clear();
NestorLDS 0:356be0c38cf1 325
NestorLDS 0:356be0c38cf1 326 lcd.refresh();
NestorLDS 0:356be0c38cf1 327 }
NestorLDS 0:356be0c38cf1 328
NestorLDS 0:356be0c38cf1 329 if (variableReading >0.3 && variableReading <0.6) {
NestorLDS 0:356be0c38cf1 330 //This is the RADAR option
NestorLDS 0:356be0c38cf1 331 lcd.drawCircle(WIDTH/11,HEIGHT/1.97,5,1); // x,y,radius,black fill
NestorLDS 0:356be0c38cf1 332 ledLaserA();
NestorLDS 0:356be0c38cf1 333 lcd.refresh();
NestorLDS 0:356be0c38cf1 334 ledLaserB();
NestorLDS 0:356be0c38cf1 335 lcd.drawCircle(WIDTH/11,HEIGHT/1.97,5,1); // x,y,radius,black fill
NestorLDS 0:356be0c38cf1 336 lcd.refresh();
NestorLDS 0:356be0c38cf1 337
NestorLDS 0:356be0c38cf1 338 while(buttonAltFlag == 1) {
NestorLDS 0:356be0c38cf1 339 lcd.clear();
NestorLDS 0:356be0c38cf1 340 //buzzer.beep(200,1.5);
NestorLDS 0:356be0c38cf1 341 inLeds = 1;
NestorLDS 0:356be0c38cf1 342 if(LedFlag) { //if flag has been set
NestorLDS 0:356be0c38cf1 343 inLeds = inLeds + 1;
NestorLDS 0:356be0c38cf1 344 if(inLeds < 3) {
NestorLDS 0:356be0c38cf1 345 inLeds = 0;
NestorLDS 0:356be0c38cf1 346 }
NestorLDS 0:356be0c38cf1 347 LedFlag = 0; //reset flag
NestorLDS 0:356be0c38cf1 348 }
NestorLDS 0:356be0c38cf1 349 int distReading = srf02.getDistanceCm();
NestorLDS 0:356be0c38cf1 350
NestorLDS 0:356be0c38cf1 351 lcd.clear();
NestorLDS 0:356be0c38cf1 352
NestorLDS 0:356be0c38cf1 353 char stringBuffer[14];
NestorLDS 0:356be0c38cf1 354
NestorLDS 0:356be0c38cf1 355 lcd.printString("Measured range",0,2);
NestorLDS 0:356be0c38cf1 356
NestorLDS 0:356be0c38cf1 357 sprintf(stringBuffer,": %d cm",distReading);
NestorLDS 0:356be0c38cf1 358
NestorLDS 0:356be0c38cf1 359 lcd.printString(stringBuffer,0,3);
NestorLDS 0:356be0c38cf1 360 lcd.refresh();
NestorLDS 0:356be0c38cf1 361
NestorLDS 0:356be0c38cf1 362 if (distReading <=15) {
NestorLDS 0:356be0c38cf1 363 pcbLEDS = 8;
NestorLDS 0:356be0c38cf1 364 wait_ms(300);
NestorLDS 0:356be0c38cf1 365 }
NestorLDS 0:356be0c38cf1 366 if (distReading > 15 && distReading <= 30) {
NestorLDS 0:356be0c38cf1 367 pcbLEDS = 12;
NestorLDS 0:356be0c38cf1 368 wait_ms(300);
NestorLDS 0:356be0c38cf1 369 }
NestorLDS 0:356be0c38cf1 370 if (distReading > 30 && distReading <= 50) {
NestorLDS 0:356be0c38cf1 371 pcbLEDS = 14;
NestorLDS 0:356be0c38cf1 372 wait_ms(300);
NestorLDS 0:356be0c38cf1 373 }
NestorLDS 0:356be0c38cf1 374 if (distReading > 50 && distReading <= 50) {
NestorLDS 0:356be0c38cf1 375 pcbLEDS = 15;
NestorLDS 0:356be0c38cf1 376 wait_ms(300);
NestorLDS 0:356be0c38cf1 377 } else {
NestorLDS 0:356be0c38cf1 378 //pcbLEDS = 15;
NestorLDS 0:356be0c38cf1 379 // wait_ms(300);
NestorLDS 0:356be0c38cf1 380 // pcbLEDS = 0;
NestorLDS 0:356be0c38cf1 381 ledFlow();
NestorLDS 0:356be0c38cf1 382 }
NestorLDS 0:356be0c38cf1 383 lcd.refresh();
NestorLDS 0:356be0c38cf1 384
NestorLDS 0:356be0c38cf1 385 // if (distReading < 35) {
NestorLDS 0:356be0c38cf1 386 // buzzer.beep(500,1.0);
NestorLDS 0:356be0c38cf1 387 // pcbLEDS = 14;
NestorLDS 0:356be0c38cf1 388 // wait_ms(300);
NestorLDS 0:356be0c38cf1 389 //
NestorLDS 0:356be0c38cf1 390 // if (distReading < 25) {
NestorLDS 0:356be0c38cf1 391 // buzzer.beep(1000,1.0);
NestorLDS 0:356be0c38cf1 392 // pcbLEDS = 12;
NestorLDS 0:356be0c38cf1 393 // wait_ms(300);
NestorLDS 0:356be0c38cf1 394 //
NestorLDS 0:356be0c38cf1 395 // if (distReading < 15) {
NestorLDS 0:356be0c38cf1 396 // buzzer.beep(9000,1.0);
NestorLDS 0:356be0c38cf1 397 // pcbLEDS = 8;
NestorLDS 0:356be0c38cf1 398 // wait_ms(300);
NestorLDS 0:356be0c38cf1 399 // } //close dist reading 15
NestorLDS 0:356be0c38cf1 400 // lcd.refresh();
NestorLDS 0:356be0c38cf1 401 // } //close dist reading 35
NestorLDS 0:356be0c38cf1 402 // } //close button flag 1
NestorLDS 0:356be0c38cf1 403 // } //close variable reading 0.3 to 0.6
NestorLDS 0:356be0c38cf1 404 lcd.refresh();
NestorLDS 0:356be0c38cf1 405 }
NestorLDS 0:356be0c38cf1 406 }
NestorLDS 0:356be0c38cf1 407
NestorLDS 0:356be0c38cf1 408 if (variableReading >= 0.6) {
NestorLDS 0:356be0c38cf1 409 //This is the the SETTINGS option
NestorLDS 0:356be0c38cf1 410 lcd.drawCircle(WIDTH/11,HEIGHT/1.2,5,1); // x,y,radius,black fill
NestorLDS 0:356be0c38cf1 411 if(refLedFlag == 1) {
NestorLDS 0:356be0c38cf1 412 ledLaserA();
NestorLDS 0:356be0c38cf1 413 lcd.refresh();
NestorLDS 0:356be0c38cf1 414 ledLaserB();
NestorLDS 0:356be0c38cf1 415 refLedFlag = 0;
NestorLDS 0:356be0c38cf1 416 }
NestorLDS 0:356be0c38cf1 417 lcd.refresh();
NestorLDS 0:356be0c38cf1 418 lcd.drawCircle(WIDTH/11,HEIGHT/1.2,5,1); // x,y,radius,black fill
NestorLDS 0:356be0c38cf1 419 //lcd.printString("SETTINGS",20,5); //X,Y axis
NestorLDS 0:356be0c38cf1 420 // buzzer.beep(12000,1.0);
NestorLDS 0:356be0c38cf1 421 while(buttonSecondAltFlag == 1) {
NestorLDS 0:356be0c38cf1 422 lcd.clear();
NestorLDS 0:356be0c38cf1 423 variableReading = pot.read(); // This, has to beinside the while loop as otherwise it would not bear it in mind when coding
NestorLDS 0:356be0c38cf1 424 lcd.setBrightness(variableReading);
NestorLDS 0:356be0c38cf1 425 char stringBuffer[14];
NestorLDS 0:356be0c38cf1 426 lcd.drawRect(15,6.5,60,10,0); // filled empty rectangle Y,X,length, width,1=FILLIN/0=NON-FILLING
NestorLDS 0:356be0c38cf1 427 lcd.drawCircle(WIDTH/11,HEIGHT/4.7,5,1); // x,y,radius,transparent with outline
NestorLDS 0:356be0c38cf1 428 lcd.printString("LCD lumen",19,1);
NestorLDS 0:356be0c38cf1 429 // buzzer.beep(200,1.5);
NestorLDS 0:356be0c38cf1 430 //lcd.printString("Measured range",0,3);
NestorLDS 0:356be0c38cf1 431 float tempVarReading = variableReading * 100;
NestorLDS 0:356be0c38cf1 432 sprintf(stringBuffer,": %.1f%%",tempVarReading);
NestorLDS 0:356be0c38cf1 433 lcd.printString(stringBuffer,0,4);
NestorLDS 0:356be0c38cf1 434 lcd.refresh();
NestorLDS 0:356be0c38cf1 435 //buzzer.beep(200,1.5);
NestorLDS 0:356be0c38cf1 436 //lcd.refresh();
NestorLDS 0:356be0c38cf1 437 wait(0.4);
NestorLDS 0:356be0c38cf1 438
NestorLDS 0:356be0c38cf1 439 // // wait(0.5);
NestorLDS 0:356be0c38cf1 440 } //close while buttonSecondAltFlag
NestorLDS 0:356be0c38cf1 441 } //close if var reading greater than 0.6
NestorLDS 0:356be0c38cf1 442 } //close while(1)
NestorLDS 0:356be0c38cf1 443 }//close main
NestorLDS 0:356be0c38cf1 444
NestorLDS 0:356be0c38cf1 445 //}
NestorLDS 0:356be0c38cf1 446 }
NestorLDS 0:356be0c38cf1 447