First Draft, serial print change based on distance

Files at this revision

API Documentation at this revision

Comitter:
liam94
Date:
Fri Feb 04 18:30:13 2022 +0000
Parent:
16:af15244242c2
Commit message:
final update to all comments

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
diff -r af15244242c2 -r 02676e9bbc73 main.cpp
--- a/main.cpp	Fri Feb 04 16:29:33 2022 +0000
+++ b/main.cpp	Fri Feb 04 18:30:13 2022 +0000
@@ -11,8 +11,8 @@
 * and back buttons it is sent to the specific start and back functions which sets
 * the flags which are then used in other functions.
 *
-* the Ultrasonic.startUpdates() is where the ultrasonic sensor is told to start measuring
-* the distances.
+* the Ultrasonic.startUpdates() is where the ultrasonic sensor is told to start 
+* measuring the distances.
 * the joystick and lcd are then initialised and the main menu function is then
 * called.
 *
@@ -58,7 +58,7 @@
 /***************************************************************************//**
 *
 * this function is the main menu for the program, it is called at the start and 
-* depending on what string is selected, clicking the start uton will send the
+* depending on what string is selected, clicking the start button will send the
 * user to the specified function.
 *
 *******************************************************************************/      
@@ -68,13 +68,13 @@
     // printf("main menu");
     
     lcd.clear();
-    Start_flag = 0;
-    int select = 0;
+    Start_flag = 0; // make sure this is set to 0 to begin with so that it doesnt operate erroneously
+    int select = 0; // always want the main menu to start on the same value on reset/ returning from a different screen
     LEDS = 63; // 63 on the bus output sets all LEDs to off
 
     while (1) {
         
-    Direction d = joystick.get_direction();   
+    Direction d = joystick.get_direction();  
     // printf("Direction = %i\n",d);
     
         switch(select) {
@@ -137,7 +137,11 @@
 
 /***************************************************************************//**
 *
-* this function is for sensing the object
+* this function is for sensing the object, a switch statement is utilised here 
+* just as it was in the main menu but here it is used for indicating the six 
+* seperate readings that are to be taken.
+* the start button is used to take the measuement and the R button is used to
+* rotate the object
 *
 *******************************************************************************/ 
 
@@ -150,8 +154,8 @@
     
     while(1)
     {
-    LEDS = fsm[state];  // output current state
-     printf("state = %d\r\n",state);
+    LEDS = fsm[state];  // this sets the LED bus output current state of the FSM
+     //printf("state = %d\r\n",state);
     
     // check which state we are in and see which the next state should be
     switch(state) {
@@ -327,7 +331,10 @@
 
 /***************************************************************************//**
 *
-* this is where the magic happens
+* these functions are called when the start button is pressed oin the sense object
+* function, the purpose of these is to store the measured values for comparison
+* and to make a buzzer sound to indicate to the user that the value has been
+* measured
 *
 *******************************************************************************/
 
@@ -341,7 +348,7 @@
         wait(0.5);
         buzzer.beep(0,0);
         
-        printf("distance at sense 1 = %d\r\n", Distance1);
+        //printf("distance at sense 1 = %d\r\n", Distance1);
 
         }
 
@@ -355,7 +362,7 @@
         wait(0.5);
         buzzer.beep(0,0);
 
-        printf("distance at sense 2 = %d\r\n", Distance2);
+        //printf("distance at sense 2 = %d\r\n", Distance2);
 
         }
         
@@ -369,7 +376,7 @@
         wait(0.5);
         buzzer.beep(0,0);
 
-        printf("distance at sense 3 = %d\r\n", Distance3);
+        //printf("distance at sense 3 = %d\r\n", Distance3);
   
         }
         
@@ -383,7 +390,7 @@
         wait(0.5);
         buzzer.beep(0,0);
 
-        printf("distance at sense 4 = %d\r\n", Distance4);
+        //printf("distance at sense 4 = %d\r\n", Distance4);
      
         }
         
@@ -397,7 +404,7 @@
         wait(0.5);
         buzzer.beep(0,0);
         
-        printf("distance at sense 5 = %d\r\n", Distance5);
+        //printf("distance at sense 5 = %d\r\n", Distance5);
      
         }
         
@@ -411,10 +418,20 @@
         wait(0.5);
         buzzer.beep(0,0);
         
-        printf("distance at sense 6 = %d\r\n", Distance6);
+        //printf("distance at sense 6 = %d\r\n", Distance6);
  
         }
-        
+
+/***************************************************************************//**
+*
+* the object detection function is where the comparison between the measured
+* values and the defined object arrays occurs, if the measured values match the
+* arrays then the program will see it as an object found and will display this on
+* the screen, otherwise it will ask the user to try again. a +/- 5mm deadband has
+* been added to allow for minor erros in the measured values.
+*
+*******************************************************************************/
+
 void object_detection(){
             
             lcd.clear();
@@ -423,25 +440,25 @@
             //printf("glass[0] = %d\n", glass[0]);
             //printf("glass[6] = %d\n", glass[6]);
             if (abs(Distance1 - glass[0]) <= 5 and abs(Distance2 - glass[1]) <= 5 and abs(Distance3 - glass[2]) <= 5 and abs(Distance4 - glass[3]) <= 5 and abs(Distance5 - glass[4]) <= 5 and abs(Distance6 - glass[5]) <= 5){       
-            printf("glass\n");
+            //printf("glass\n");
             lcd.printString(" Object Found!",0,1);
             lcd.printString("  Pint Glass",0,3);
             lcd.refresh();}
             
             else if (abs(Distance1 - firestick_box[0]) <= 5 and abs(Distance2 - firestick_box[1]) <= 5 and abs(Distance3 - firestick_box[2]) <= 5 and abs(Distance4 - firestick_box[3]) <= 5 and abs(Distance5 - firestick_box[4]) <= 5 and abs(Distance6 - firestick_box[5]) <= 5){       
-            printf("Firestick Box\n");
+            //printf("Firestick Box\n");
             lcd.printString(" Object Found!",0,1);
             lcd.printString(" Firestick Box",0,3);
             lcd.refresh();}
             
             else if (abs(Distance1 - Disaronno_bottle[0]) <= 5 and abs(Distance2 - Disaronno_bottle[1]) <= 5 and abs(Distance3 - Disaronno_bottle[2]) <= 5 and abs(Distance4 - Disaronno_bottle[3]) <= 5 and abs(Distance5 - Disaronno_bottle[4]) <= 5 and abs(Distance6 - Disaronno_bottle[5]) <= 5){       
-            printf("Firestick Box\n");
+            //printf("Disaronno Bottle\n");
             lcd.printString(" Object Found!",0,1);
-            lcd.printString(" Firestick Box",0,3);
+            lcd.printString("  Disaronno!",0,3);
             lcd.refresh();}
                      
             else{
-            printf("nothing\n");
+            //printf("nothing\n");
             lcd.printString("  No Object!",0,1);
             lcd.printString("  Please Try",0,3);
             lcd.printString("Again",24,4);
diff -r af15244242c2 -r 02676e9bbc73 main.h
--- a/main.h	Fri Feb 04 16:29:33 2022 +0000
+++ b/main.h	Fri Feb 04 18:30:13 2022 +0000
@@ -43,12 +43,12 @@
 
 /***************************************************************************//**
 *
-* below is array of states for the LEDs in the FSM, states have been defined in
-* binary for ease of use, 0 is LED on, 1 is LED off so only one LED is on in any
-* state. the member functions that are to be used in the main source code file
-* have also been defined and the ultrasonice sensor trigger and echo pin have 
-* been defined, it updates every .5 seconds and a timeout after 1 second and call 
-* the function dist when the distance changes.
+* below is a list of integars that have been defined, three objects have been 
+* defined that will be used for the comparison to the sensed values later on in 
+* the code. also there is an array of states for the LEDs in the FSM, states have 
+* been defined in binary for ease of use, 0 is LED on, 1 is LED off so only one
+* LED is on in any state. the distance and flag integars have also been defined 
+* here but given no value, this is because these will be set later in the code.
 *
 *******************************************************************************/
 
@@ -64,6 +64,15 @@
 
 int Start_flag, Back_flag;
 
+/***************************************************************************//**
+*
+* below the member functions that are to be used in the main source code file 
+* have also been defined and the ultrasonice sensor trigger and echo pin have 
+* been defined, it updates every .5 seconds and a timeout after 1 second and call
+* the function dist when the distance changes.
+*
+*******************************************************************************/
+
 void init_display();
 
 void main_menu();