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-JDB SRF02 SoftPWM-JDB TMP102 mbed
main.cpp
00001 /* 00002 00003 ELEC2645 - Embedded Systems Project - "Sensor-matic!" 00004 00005 Distance and Temperature Sensors Displayed on Nokia 5110 Screen 00006 00007 00008 Week 19 - Testing SRF02 Distance Sensor 00009 00010 Week 20 - Creating Splash Screens 00011 00012 Week 21 - Diagrams for Temperature and Distance 00013 00014 Easter - Navigation Between Menus 00015 00016 Week 22 - Piezo/LEDs Interfaced 00017 00018 Week 23 - DOxygen Commenting 00019 00020 Week 24 - Cleaning Up & Submission 00021 00022 00023 (c) Jack Berriman, University of Leeds, Summer 2016 00024 00025 */ 00026 00027 /** 00028 @file main.cpp 00029 @brief Program Implementation 00030 */ 00031 00032 00033 #include "main.h" 00034 00035 00036 // ------------------------- MAIN FUNCTION ------------------------- // 00037 00038 int main() // Main Function 00039 { 00040 00041 init_K64F(); // Initialise FRDM K64F Micrcontroller 00042 init_buzzer(); // Initialise Piezo Buzzer 00043 init_program(); // Initialise Other Program Requirements (Screen/Ticker/Baud Rate) 00044 00045 welcomeScreen(); // Display Welcome Screen 00046 screen.clear(); // Clear Screen 00047 00048 while (1) { // Infinite Program While Loop 00049 00050 if (screenNumber == 0) { // Main Menu = 0 00051 mainMenu(); 00052 } else if (screenNumber == 1) { // Sensor Menu = 1 00053 sensorMenu(); 00054 } else if (screenNumber == 2) { // Options Menu = 2 00055 optionsMenu(); 00056 } else if (screenNumber == 3) { // Distance Display = 3 00057 distanceDisplay(); 00058 } else { // Temperature Display = 4 00059 temperatureDisplay(); 00060 } 00061 00062 screen.refresh(); // Refresh Screen AFTER Each Iteration 00063 sleep(); // Put Peripherals To Sleep (Due to InterruptIn) 00064 00065 } 00066 } 00067 00068 00069 // ------------------------- INITIALISE FUNCTIONS ------------------------- // 00070 00071 void clearAll() // Clears Current Buffer (Text/Pixels) -- ADAPTED FROM ELEC1620 (GAME OF LIFE PROJECT) 00072 { 00073 for (int xPixel = 0; xPixel < 84; xPixel++) { // Loops Through X-Pixels 00074 for (int yPixel = 0; yPixel < 48; yPixel++) { // Loops Through Y-Pixels 00075 screen.clearPixel(xPixel,yPixel); // Clears 00076 } 00077 } 00078 screen.refresh(); // Refreshes Screen AFTER Clearing 00079 } 00080 00081 00082 void init_K64F() // Initialise K64F Function 00083 { 00084 // On-Board LEDs are Active-Low 00085 r_led = 1; 00086 g_led = 1; // Set to 1 (High) to Turn OFF 00087 b_led = 1; 00088 00089 allLEDOff(); // Turn off All LEDs 00090 00091 forward.rise(&forward_isr); // Interrupts Fire on Rising Clock Edge 00092 backward.rise(&backward_isr); 00093 00094 forward.mode(PullDown); // Push Buttons are Connected to +3V3 - Pull-Down to Ground when Pressed 00095 backward.mode(PullDown); 00096 } 00097 00098 00099 void init_buzzer() // Initialise Piezo Buzzer Function 00100 { 00101 piezo.period(1.0/2000.0); // Set Frequency to 2 kHz 00102 piezo.write(0.0); // Turn OFF (Duty Cycle = 0) 00103 } 00104 00105 00106 void init_program() // Initialise Other Program Requirements 00107 { 00108 screen.init(); // Initialise Screen 00109 screen.clear(); // Clear Buffer 00110 systemTicker.attach(&system_isr,0.5); // Attach Ticker 00111 pc.baud(115200); // Set Serial Port Baud Rate to 115200 Hz 00112 } 00113 00114 00115 void welcomeScreen() // Prints Welcome Screen on Start-Up 00116 { 00117 00118 // printString is a function from N5110.h 00119 screen.printString("ELEC2645", 20, 0); // Format: screen.printString("Text", Number of Pixels 'in' (X-Position), Bank Number (Y-Position)) 00120 screen.printString("Sensor-matic!", 5, 2); // Project Title 00121 screen.printString("By", 35, 4); 00122 screen.printString("Jack Berriman", 3, 5); 00123 00124 wait(2); // Delay (To Read Text) 00125 00126 } 00127 00128 00129 // ------------------------- STRUCTS ------------------------- // 00130 00131 AverageValues getAverageValues() // Struct for Calculating Average Values of Distance and Temperature 00132 { 00133 AverageValues values; // Access Struct 00134 int temporaryDistanceSum = 0; 00135 int temporaryTemperatureSum = 0; // Initialise Temporary 'Sum' Variables Equal to Zero 00136 00137 for (int i = 0; i <= 10; i++) { // Loop Through 10 Samples 00138 00139 int distanceRead = srf02.getDistanceCm(); // Each Iteration: Get Distance and Write to Variable 'distanceRead' 00140 temporaryDistanceSum += distanceRead; // Add to Sum 00141 00142 int temperatureRead = tmp102.get_temperature(); // Each Iteration: Get Temperature and Write to Variable 'distanceRead' 00143 temporaryTemperatureSum += temperatureRead; // Add to Sum 00144 } 00145 00146 values.averageDistance = temporaryDistanceSum/10; // Divide by Number of Samples (10) 00147 values.averageTemperature = temporaryTemperatureSum/10; 00148 00149 return values; // Return 'values' to Struct 00150 } 00151 00152 00153 // ------------------------- CURSOR POSITION (POTENTIOMETER) FUNCTIONS ------------------------- // 00154 00155 int getCursorPosition() // Read Potentiometer Value & Convert to Bank Value 00156 { 00157 int bank = floor(controller * 5) + 1; // Read Potentioementer & Multiply by 5 00158 // 'Floor' = Rounds Down 00159 00160 if (bank == 6) { // If Bank value us greater that 5... 00161 bank = 5; // A value of 5 is returned 00162 } 00163 00164 return bank; // Return Bank Value 00165 } 00166 00167 00168 void printCursorPositionMain(int cursor) // Print Cursor as Rectangle Next to Option in Main/Sensor Menu (Used with 'getCursorPosition') 00169 { 00170 // Prevents Cursor Position From Being Unselectable 00171 if (cursor != 1 && cursor != 3 && cursor != 5) { // If Cursor in Banks 2 or 4 - Print Rectangle 00172 00173 y_axis_rect_main = (cursor * 8) + 3; // Multiply Cursor by 8 to Return Y-Position & Add 3 to Align in Bank 00174 00175 screen.drawRect(75,y_axis_rect_main,2,2,0); // Print Rectangle (Depending on Potentiometer/Cursor) 00176 } else { 00177 screen.drawRect(75,y_axis_rect_main,2,2,0); // If Bank is 1, 3 or 5 - Still Print Rectangle 00178 } 00179 } 00180 00181 00182 void printCursorPositionOptions(int cursor, int stateOfLED, int stateOfSound) // Print Cursor as Rectangle Next to Option in Options Menu (Used with 'getCursorPosition') 00183 { 00184 // stateOfLed & stateOfSound Return 1 or 0 00185 // 1 or 0 Passed into 'drawRect' - Fills or Unfills Rectangle 00186 00187 y_axis_rect_options = (cursor * 8) + 3; // Multiply Cursor by 8 to Return Y-Position & Add 3 to Align in Bank 00188 cursor == 1 ? screen.drawRect(81,y_axis_rect_options,2,2,stateOfLED):screen.drawRect(81,y_axis_rect_options,2,2,stateOfSound); 00189 // If Cursor is 1 = Draw Rectangle OR If Cursor is 3 = Draw Rectangle 00190 } 00191 00192 00193 // ------------------------- MENU FUNCTIONS (MAIN/SENSORS/OPTIONS ------------------------- // 00194 00195 void mainMenu() // Function for Main Menu 00196 { 00197 y_axis_rect_main = 19; // Set Initial Y-Position to 19th Pixel 00198 00199 while (screenNumber == 0) { // While Main Menu Screen On... 00200 00201 int cursor = getCursorPosition(); // Read Position of Cursor 00202 00203 if (g_system_flag) { 00204 g_system_flag = 0; // Reset System Flag to 0 00205 00206 clearAll(); // Clears Previous Text String (Welcome Screen) 00207 00208 screen.printString("MAIN MENU", 16, 0); // Print String 'Main Menu' 00209 screen.drawLine(5,11,79,11,1); // Draw Line Above Sensors String 00210 screen.printString("Sensors", 3, 2); // Print String 'Sensors' 00211 screen.printString("Options", 3, 4); // Print String 'Options' 00212 screen.drawLine(5,44,79,44,1); // Draw Line Underneath Options String 00213 00214 // Used to Ensure Cursor is Set in Bank 00215 if (cursor <= 2) { // If Position of Cursor is 2 or Less 00216 cursor = 2; // Set Cursor to Equal 2 00217 } 00218 if (cursor >= 3) { // If Position of Cursor is 3 or Greater 00219 cursor = 4; // Set Cursor to Equal 4 00220 } 00221 00222 printCursorPositionMain(cursor); // Print Cursor to Screen 00223 pc.printf("Controller = %d \n",cursor); // Debug in 'CoolTerm.exe' 00224 00225 // Check Flag IF 'forward' Button Interrupt Pressed 00226 if (g_forward_flag == 1) { 00227 g_forward_flag = 0; // Clear Flag 00228 00229 // Determine Next Screen 00230 if (cursor == 2) { 00231 screenNumber = 1; // Go to Sensor Menu 00232 } 00233 if (cursor == 4) { 00234 screenNumber = 2; // Go to Options Menu 00235 } 00236 } 00237 } 00238 returnToMenu(); // Back Button Function 00239 screen.refresh(); // Refresh Screen 00240 } 00241 } 00242 00243 void sensorMenu() // Function for Sensor Menu 00244 { 00245 while (screenNumber == 1) { // While Sensor Menu is On... 00246 00247 int cursor = getCursorPosition(); // Read Position of Cursor 00248 00249 if (g_system_flag) { 00250 g_system_flag = 0; // Reset System Flag to 0 00251 00252 clearAll(); // Clears Previous Text String (Main Menu Screen) 00253 00254 screen.printString("SENSOR MENU", 10, 0); // Prints String 'SensorMenu' 00255 screen.drawLine(5,11,79,11,1); // Draw Line Above Dist Sensor 00256 screen.printString("Dist Sensor", 3, 2); // Prints String 'Dist Sensor' 00257 screen.printString("Temp Sensor", 3, 4); // Prints String 'Temper Sensor' 00258 screen.drawLine(5,44,79,44,1); // Draw Line Below Temp Sensor 00259 00260 // Used to Ensure Cursor is Set in Bank 00261 if (cursor <= 2) { // If Position of Cursor is 2 or Less 00262 cursor = 2; // Set Cursor to Equal 2 00263 } 00264 if (cursor >= 3) { // If Position of Cursor is 3 or Greater 00265 cursor = 4; // Set Cursor to Equal 4 00266 } 00267 00268 printCursorPositionMain(cursor); // Print Cursor to Screen 00269 pc.printf("Controller = %d \n",cursor); // Debug in 'CoolTerm.exe' 00270 00271 // Check Flag IF 'forward' Button Interrupt Pressed 00272 if (g_forward_flag == 1) { 00273 g_forward_flag = 0; // Clear Flag 00274 00275 // Determine Next Screen 00276 if (cursor == 2) { 00277 screenNumber = 3; // Go to Distance Display 00278 } 00279 if (cursor == 4) { 00280 screenNumber = 4; // Go to Temperature Display 00281 } 00282 } 00283 } 00284 returnToMenu(); // Back Button Function 00285 screen.refresh(); // Refresh Screen 00286 } 00287 } 00288 00289 void optionsMenu() // Function for Options Menu 00290 { 00291 y_axis_rect_options = 27; // Set Initial Y-Position to 27th Pixel 00292 00293 while (screenNumber == 2) { // While Options Menu is On... 00294 00295 int cursor = getCursorPosition(); // Read Position of Cursor 00296 00297 if (g_system_flag) { 00298 g_system_flag = 0; // Reset System Flag to 0 00299 00300 clearAll(); // Clears Previous Text String (Main Menu Screen) 00301 00302 screen.printString("Toggle LEDs", 1, 1); // Print String 'Toggle LEDs' 00303 screen.printString("Toggle Sound", 1, 3); // Print String 'Toggle Sound' 00304 screen.printString("Toggle Colour", 1, 5); // Print String 'Toggle Colour' 00305 00306 // Used to Ensure Cursor is Set in Bank 00307 if (cursor <= 2) { // If Position of Cursor is 2 or Less 00308 cursor = 1; // Set Cursor to Equal 1 00309 } 00310 if (cursor > 2 && cursor <= 4) { // If Position of Cursor is Between 2 or 4 00311 cursor = 3; // Set Cursor to Equal 3 00312 } 00313 if (cursor > 4) { // If Position of Cursor is Greater than 4 00314 cursor = 5; // Set Cursor to Equal 5 00315 } 00316 00317 if (triggerLEDs == 1) { // Read Trigger of LED 00318 allLEDOn(); // If Trigger = 1, Turn ON LEDs 00319 } 00320 00321 printCursorPositionOptions(cursor, stateOfLED, stateOfSound); // Print Position of Cursor 00322 00323 // Check Flag IF 'forward' Button Interrupt Pressed 00324 if (g_forward_flag == 1) { 00325 g_forward_flag = 0; // Clear Flag 00326 00327 // Determine Options to Edit 00328 if (cursor == 1) { 00329 stateOfLED = toggleLEDs(); // Toggle LEDs & Write 1 or 0 to 'stateOfLED' 00330 } 00331 if (cursor == 3) { 00332 stateOfSound = toggleSound(); // Toggle Sound & Write 1 or 0 to 'stateOfLED' 00333 } 00334 if (cursor == 5) { 00335 toggleColour(); // Toggle Colour 00336 } 00337 } 00338 } 00339 returnToMenu(); // Back Button Function 00340 screen.refresh(); // Refresh Screen 00341 } 00342 } 00343 00344 void distanceDisplay() // Function to Display Distance 00345 { 00346 AverageValues values; // Call Struct For Average Values 00347 00348 while(screenNumber == 3) { // While Temperature Display is On... 00349 00350 values = getAverageValues(); 00351 int Distance = values.averageDistance; // Access Struct Value 00352 00353 if (g_system_flag) { 00354 g_system_flag = 0; // Reset System Flag to 0 00355 00356 clearAll(); 00357 00358 if (triggerLEDs == 1) { 00359 LEDs_Distance(Distance); // Call Distance LED Function 00360 } 00361 00362 char buffer[14]; // Each Character = 6 pixels wide & Screen = 84 pixels (84/6 = 14) 00363 int length = sprintf(buffer,"Dist = %d CM",Distance); // Print Distance Value to Buffer 00364 pc.printf("DistAv = %f \n DistNorm = %f \n", Distance, srf02.getDistanceCm()); // Debug in 'CoolTerm.exe' 00365 00366 if (length <= 14) // If String Fits on Display 00367 screen.printString(buffer,3,2); // Display on Screen 00368 00369 if (Distance <= 14 || Distance >= 250) { // If Sensor is Out of Range 00370 clearAll(); // Clear Buffer 00371 screen.drawLine(4,2,80,2,2); // Draw Dotted Line Above Text 00372 screen.printString("DISTANCE OUT", 6, 1); 00373 screen.printString("OF RANGE", 18, 2); 00374 screen.drawLine(4,27,80,27,2); // Draw Dotted Line Below Text 00375 screen.printString("MIN = 15 CM", 10, 4); 00376 screen.printString("MAX = 250 CM", 7, 5); 00377 00378 if (triggerSound == 1) { // Play Continuous Buzz When Out of Range 00379 buzzerOn(); 00380 } 00381 } else { // If Sensor is In Range 00382 00383 screen.printString("DIST SENSOR", 10, 0); // Print String 'Distance Sensor' (Title) 00384 00385 screen.drawRect(5,26,74,12,0); // Draw Rectangle Outline 00386 int fillLength = floor(PIXEL_PER_CM * Distance); // Update Fill Length Depending on Distance Value 00387 00388 screen.drawRect(6,27,fillLength,11,1); // Fill the Distance Bar (Left to Right) 00389 00390 screen.drawRect(17,26,2,12,0); // Puts in Dividers at 50 cm Intervals 00391 screen.drawRect(33,26,2,12,0); 00392 screen.drawRect(48,26,2,12,0); 00393 screen.drawRect(63,26,2,12,0); 00394 00395 screen.printString("15",0,5); // Prints Lower Bound Marker (15 cm) 00396 screen.printString("250",67,5); // Prints Upper Bound Marker (250 cm) 00397 00398 if (Distance <= 50) { 00399 if (triggerSound == 1) { // Check Trigger Value of Buzzer 00400 buzzerClose(); // Play Highly Freuquent Buzz 00401 } 00402 } else if (Distance <= 100) { 00403 if (triggerSound == 1) { // Check Trigger Value of Buzzer 00404 buzzerNormal(); // Play Moderately Freuquent Buzz 00405 } 00406 } else if (Distance <= 200) { 00407 if (triggerSound == 1) { // Check Trigger Value of Buzzer 00408 buzzerFar(); // Play Lowly Freuquent Buzz 00409 } 00410 } 00411 } 00412 00413 00414 returnToMenu(); // Function for Back Button 00415 screen.refresh(); // Refreshes Screen 00416 } 00417 } 00418 } 00419 00420 void temperatureDisplay() // Function to Display Temperature 00421 { 00422 AverageValues values; // Call Struct For Average Values 00423 00424 while(screenNumber == 4) { // While Temperature Display is On... 00425 00426 values = getAverageValues(); 00427 int Temperature = values.averageTemperature; // Access Struct Value 00428 00429 if (g_system_flag) { 00430 g_system_flag = 0; // Reset System Flag to 0 00431 00432 clearAll(); // Clears Previous Text String (Sensor Menu Screen) 00433 00434 screen.printString("TEMP SENSOR", 10, 0); // Print String 'Temp Sensor' (Title) 00435 00436 LEDs_Temperature(Temperature); // Call Temperature LED Function 00437 00438 char buffer[14]; // Each Character = 6 pixels wide & Screen = 84 pixels (84/6 = 14) 00439 int length = sprintf(buffer,"Temp = %d -C",Temperature); // Print Temperature Value to Buffer 00440 pc.printf("TempAv = %f \n TempNorm = %f \n", Temperature, tmp102.get_temperature()); // Debug in 'CoolTerm.exe' 00441 00442 if (length <= 14) // If String Fits on Display 00443 screen.printString(buffer,6,2); // Display on Screen 00444 00445 screen.drawCircle(15,36,7,1); // Circular End of Thermometer 00446 screen.drawRect(22,32,6,8,1); // Start of Thermometer 00447 screen.drawRect(26,32,48,8,0); // Outline of the Thermometer 00448 00449 int fillLength = floor(PIXEL_PER_DEGREE * Temperature); // Update Fill Length Depending on Thermometer Value 00450 00451 screen.drawRect(27,33,fillLength,6,1); // Fill the Thermometer (Left to Right) 00452 screen.refresh(); // Refresh Screen 00453 } 00454 returnToMenu(); // Function for Back Button 00455 } 00456 } 00457 00458 00459 // ------------------------- OPTIONS MENU (TOGGLE) FUNCTIONS ------------------------- // 00460 00461 bool toggleLEDs() // Toggles LED (Enable/Disable) 00462 { 00463 if (triggerLEDs == 0) { 00464 allLEDOn(); // Turn ON LEDs (While on Options Screen) 00465 triggerLEDs = 1; // 'Flip' Trigger 00466 } else { 00467 allLEDOff(); // Turn OFF LEDs (While on Options Screen 00468 triggerLEDs = 0; // 'Flip' Trigger 00469 } 00470 00471 bool stateOfLED = triggerLEDs; // Set Trigger Value (1 or 0) into Bool 00472 return stateOfLED; // Return Bool (Used in Printing Rectangle) 00473 } 00474 00475 00476 bool toggleSound() // Toggles Sound (Enable/Disable) 00477 { 00478 if (triggerSound == 0) { 00479 piezo.write(0.5); // Play Bleep Noise 00480 wait(0.1); 00481 piezo.write(0.0); 00482 triggerSound = 1; // 'Flip' Trigger 00483 } else { 00484 triggerSound = 0; // 'Flip' Trigger 00485 } 00486 00487 bool stateOfSound = triggerSound; // Set Trigger Value (1 or 0) into Bool 00488 return stateOfSound; // Return Bool (Used in Printing Rectangle) 00489 } 00490 00491 00492 void toggleColour() // Toggles Colour (Black-on-White/White-on-Black) 00493 { 00494 if (triggerColour == 0) { 00495 screen.inverseMode(); // Set Colour to Inverse Mode (White-on-Black) 00496 triggerColour = 1; // 'Flip' Trigger 00497 } else { 00498 screen.normalMode(); // Set Colour to Normal Mode (Black-on-White) 00499 triggerColour = 0; // 'Flip' Trigger 00500 } 00501 } 00502 00503 00504 // ------------------------- LED & SOFT-PWM FUNCTIONS ------------------------- // 00505 00506 void allLEDOn() // Function to Turn ON All LEDs 00507 { 00508 red_led = 0; 00509 yellow_led = 0; 00510 green_led = 0; 00511 } 00512 00513 00514 void allLEDOff() // Function to Turn OFF All LEDs 00515 { 00516 red_led = 1; 00517 yellow_led = 1; 00518 green_led = 1; 00519 } 00520 00521 00522 void LEDs_Flashing() 00523 { 00524 redPWM = 0.5; // Turn ON Soft PWM LEDs 00525 yellowPWM = 0.5; 00526 greenPWM = 0.5; 00527 00528 redPWM.period(0.25); // Set Period = 0.25 seconds 00529 yellowPWM.period(0.25); 00530 greenPWM.period(0.25); 00531 } 00532 00533 00534 void cancel_LEDs_Flashing() 00535 { 00536 redPWM = 0; // Turn OFF Soft PWM LEDs 00537 yellowPWM = 0; 00538 greenPWM = 0; 00539 00540 redPWM.stop(); // Stop Soft PWM 00541 yellowPWM.stop(); 00542 greenPWM.stop(); 00543 } 00544 00545 00546 void LEDs_Distance(int d) // LEDs Illuminate (Depending on Distance) 00547 { 00548 00549 if (d < 15 || d > 250) { // All ON 00550 LEDs_Flashing(); // Enable Soft PWM Flashing LEDs 00551 } else if (d >= 15 && d < 50) { // Red ON 00552 cancel_LEDs_Flashing(); // Prevent Soft PWM Overwritting Digital LEDs 00553 red_led = 0; 00554 yellow_led = 1; 00555 green_led = 1; 00556 } else if (d >= 50 && d < 100) { // Red & Yellow ON 00557 cancel_LEDs_Flashing(); 00558 red_led = 0; 00559 yellow_led = 0; 00560 green_led = 1; 00561 } else if (d >= 100 && d < 150) { // Yellow ON 00562 cancel_LEDs_Flashing(); 00563 red_led = 1; 00564 yellow_led = 0; 00565 green_led = 1; 00566 } else if (d >= 150 && d < 200) { // Yellow & Green ON 00567 cancel_LEDs_Flashing(); 00568 red_led = 1; 00569 yellow_led = 0; 00570 green_led = 0; 00571 } else if (d >= 200 && d < 250) { // Green ON 00572 cancel_LEDs_Flashing(); 00573 red_led = 1; 00574 yellow_led = 1; 00575 green_led = 0; 00576 } 00577 } 00578 00579 00580 void LEDs_Temperature(int t) // LEDs Illuminate (Depending on Temperature) 00581 { 00582 00583 if (t < 10 || t >= 40) { // All ON 00584 allLEDOn(); 00585 } else if (t >= 10 && t < 15) { // Red ON 00586 red_led = 0; 00587 yellow_led = 1; 00588 green_led = 1; 00589 } else if (t >= 15 && t < 20) { // Red & Yellow ON 00590 red_led = 0; 00591 yellow_led = 0; 00592 green_led = 1; 00593 } else if (t >= 20 && t < 25) { // Green ON 00594 red_led = 0; 00595 yellow_led = 0; 00596 green_led = 1; 00597 } else if (t >= 25 && t < 30) { // Red & Yellow ON 00598 red_led = 0; 00599 yellow_led = 0; 00600 green_led = 1; 00601 } else if (t >= 30 && t < 40) { // Red ON 00602 red_led = 0; 00603 yellow_led = 1; 00604 green_led = 1; 00605 } 00606 } 00607 00608 00609 // ------------------------- BUZZER FUNCTIONS ------------------------- // 00610 00611 void buzzerOn() // Buzz Continuously 00612 { 00613 piezo.write(0.5); // Set Duty Cycle - 50% 00614 wait_ms(10); // Wait 10 Milli-Seconds 00615 } 00616 00617 00618 void buzzerClose() // Buzz Every 0.1 Seconds 00619 { 00620 piezo.write(0.5); 00621 wait(0.1); // Wait 0.1 Seconds 00622 piezo.write(0.0); 00623 } 00624 00625 00626 void buzzerNormal() // Buzz Every 0.3 Seconds 00627 { 00628 piezo.write(0.5); 00629 wait(0.3); 00630 piezo.write(0.0); 00631 } 00632 00633 00634 void buzzerFar() // Buzz Every 0.5 Seconds 00635 { 00636 piezo.write(0.5); 00637 wait(0.5); 00638 piezo.write(0.0); 00639 } 00640 00641 00642 // ------------------------- ISR & INTERRUPT FUNCTIONS ------------------------- // 00643 00644 void returnToMenu() // Function for Returning to Main Menu (if 'backward' Button Pressed) 00645 { 00646 // Check Flag IF 'forward' Button Interrupt Pressed 00647 if (g_backward_flag) { 00648 g_backward_flag = 0; // Clear Flag 00649 00650 screenNumber = 0; // Go to Screen Number = 0 (Main Menu) 00651 cancel_LEDs_Flashing(); 00652 allLEDOff(); // Turn OFF LEDs 00653 piezo.write(0.0); // Write 0% Duty Cycle to Piezo (Turn OFF) 00654 } 00655 00656 } 00657 00658 00659 void system_isr() // ISR For 'systemTicker' 00660 { 00661 g_system_flag = 1; // Set 'systemTicker' Flag 00662 } 00663 00664 00665 void forward_isr() // ISR For 'forward' Buttom 00666 { 00667 g_forward_flag = 1; // Set 'forward' Button Flag 00668 } 00669 00670 00671 void backward_isr() // ISR For 'backward' Button 00672 { 00673 g_backward_flag = 1; // Set 'backward' Button Flag 00674 }
Generated on Tue Jul 12 2022 19:51:18 by
1.7.2