Coursework

Revision:
40:0d55297c8b34
Parent:
39:a31b49f3e65e
Child:
41:16cd48d6e834
--- a/main.cpp	Thu Feb 03 21:03:27 2022 +0000
+++ b/main.cpp	Thu Feb 03 22:03:36 2022 +0000
@@ -30,6 +30,7 @@
 volatile int LoopCountScan3;
 volatile int LoopCountScan4;
 volatile int LoopCountScan5;
+volatile int LoopCountScan6;
 volatile int g_buttonA_flag = 0; 
 volatile int g_buttonB_flag = 0; 
 volatile int g_buttonX_flag = 0; 
@@ -38,6 +39,9 @@
 volatile int g_buttonBack_flag = 0; 
 volatile int g_buttonLeft_flag = 0; 
 volatile int g_buttonRight_flag = 0;
+volatile int wallTotal;
+volatile int boxTotal;
+volatile int cartonTotal;
 /**
 *..Bring in 5 arrays of 5 for each of the 5 required scans.
 *..array Ref starts at 0,
@@ -97,9 +101,11 @@
 void inputScan3();
 void inputScan4();
 void inputScan5();
+void inputScan6();
 int NoContinueExit();
 int buttonCountA();
 int buttonCountB();
+void printShape();
 
 
 
@@ -396,6 +402,7 @@
      LoopCountScan3 =0;
      LoopCountScan4 =0;
      LoopCountScan5 =0;
+     LoopCountScan6 =0;
      
 
         
@@ -906,59 +913,14 @@
      
      case 6:
      g_ButtonAPress=6;
+                       if(LoopCountScan6==10){
+        g_ButtonAPress=0;
+        LoopCountScan6=0;
+        break;}
+        else;
              
- int box[5]= {90,10,10,90,90};// compared to the wall if the box is present this sequence should be recorded
- int carton[5] = {10,10,10,10,10}; // compared to the carton if the box is present this sequence should be recorded
- int wall [5] = {90,90,90,90,90}; // compared to the carton if the box is present this sequence should be recorded
- int isBox[5];
- int isCarton[5];
- int isWall[5];
- int wallTotal;
- int cartonTotal;
- int boxTotal;
- for (int i=0; i<5; i++){
-   isBox[i] =abs(Scan1[i]-box[i]);
-   printf("DeBUGGING isBOX : %i\n", isBox[i]);
-    if (isBox[i]<=5){
-    isBox[i]=0;}
-else if (isBox[i]>5){
-isBox[i]=1;}
-printf("DeBUGGING isBOX : %i\n", isBox[i]);
-boxTotal = accumulate(begin(isBox), end(isBox), 0, plus<int>());
-printf("DEBUGGING BOX total %i\n", boxTotal);
-
-  isCarton[i] =abs(Scan1[i]-carton[i]);
-   printf("DeBUGGING isCarton : %i\n", isCarton[i]);
-    if (isCarton[i]<=5){
-    isCarton[i]=0;}
-else if (isCarton[i]>5){
-isCarton[i]=1;}
-printf("DeBUGGING isCarton : %i\n", isCarton[i]);
-cartonTotal = accumulate(begin(isCarton), end(isCarton), 0, plus<int>());
-printf("DEBUGGING CARTON total %i\n", cartonTotal);
-
-  isWall[i] =abs(Scan1[i]-wall[i]);
-   printf("DeBUGGING isWall : %i\n", isWall[i]);
-    if (isWall[i]<=5){
-    isWall[i]=0;}
-else if (isWall[i]>5){
-isWall[i]=1;}
-printf("DeBUGGING isWall : %i\n", isWall[i]);
-wallTotal = accumulate(begin(isWall), end(isWall), 0, plus<int>());
-printf("DEBUGGING Wall total %i\n", wallTotal);
-
-;}
-printf("Im Free of the For Debug WallTotoal::  %i\n", wallTotal);
-printf("Im Free of the For Debug BoxTotoal::  %i\n", boxTotal);
-printf("Im Free of the For Debug cartonTotoal::  %i\n", cartonTotal);
-if(wallTotal == 0){
-     printf("We Have a wall\n");}
-     else if(boxTotal=0){
-         printf("We Have Box\n");}
-         else;
-         printf("Not in the Database \n");
-     
-        }
+       inputScan6();
+       break;
         
         /*
 int button_counter;
@@ -1062,6 +1024,7 @@
  */
  }
  }
+ }
    int buttonCountA(){
         g_ButtonAPress++;
         if (g_ButtonAPress>5){
@@ -1078,39 +1041,46 @@
         }
    int NoContinueExitScan1(){
         LoopCountScan1++;
-        if (LoopCountScan1>5){
+        if (LoopCountScan1>10){
             LoopCountScan1= 0;
             }
         return LoopCountScan1;
         }
         int NoContinueExitScan2(){
         LoopCountScan2++;
-        if (LoopCountScan2>5){
+        if (LoopCountScan2>10){
             LoopCountScan2= 0;
             }
         return LoopCountScan2;
         }
         int NoContinueExitScan3(){
         LoopCountScan3++;
-        if (LoopCountScan3>5){
+        if (LoopCountScan3>10){
             LoopCountScan3= 0;
             }
         return LoopCountScan3;
         }
            int NoContinueExitScan4(){
         LoopCountScan4++;
-        if (LoopCountScan4>5){
+        if (LoopCountScan4>10){
             LoopCountScan4= 0;
             }
         return LoopCountScan4;
         }
            int NoContinueExitScan5(){
         LoopCountScan5++;
-        if (LoopCountScan5>5){
+        if (LoopCountScan5>10){
             LoopCountScan5= 0;
             }
         return LoopCountScan5;
         }
+                   int NoContinueExitScan6(){
+        LoopCountScan6++;
+        if (LoopCountScan6>10){
+            LoopCountScan6= 0;
+            }
+        return LoopCountScan6;
+        }
         
         
    //Button A event-triggered interrupt
@@ -1311,4 +1281,69 @@
          wait_ms(5);
          Buzzer.play(200,120);  lcd.printString("X",60,5);lcd.refresh();         Scan5[4] = sensor.distance(); */
          lcd.printString("Scan 5 Done",0,0); lcd.refresh();
-    }
\ No newline at end of file
+    }
+    
+void inputScan6()
+{
+                  lcd.clear();
+        lcd.printString("Decide",0,0);
+        lcd.refresh();
+           NoContinueExitScan6();
+         int box[5]= {90,10,10,90,90};// compared to the wall if the box is present this sequence should be recorded
+ int carton[5] = {10,10,10,10,10}; // compared to the carton if the box is present this sequence should be recorded
+ int wall [5] = {90,90,90,90,90}; // compared to the carton if the box is present this sequence should be recorded
+ int isBox[5];
+ int isCarton[5];
+ int isWall[5];
+ //int wallTotal;
+ //int cartonTotal;
+ //int boxTotal;
+ for (int i=0; i<5; i++){
+   isBox[i] =abs(Scan1[i]-box[i]);
+   printf("DeBUGGING isBOX : %i\n", isBox[i]);
+    if (isBox[i]<=5){
+    isBox[i]=0;}
+else if (isBox[i]>5){
+isBox[i]=1;}
+printf("DeBUGGING isBOX : %i\n", isBox[i]);
+boxTotal = accumulate(begin(isBox), end(isBox), 0, plus<int>());
+printf("DEBUGGING BOX total %i\n", boxTotal);
+
+  isCarton[i] =abs(Scan1[i]-carton[i]);
+   printf("DeBUGGING isCarton : %i\n", isCarton[i]);
+    if (isCarton[i]<=5){
+    isCarton[i]=0;}
+else if (isCarton[i]>5){
+isCarton[i]=1;}
+printf("DeBUGGING isCarton : %i\n", isCarton[i]);
+cartonTotal = accumulate(begin(isCarton), end(isCarton), 0, plus<int>());
+printf("DEBUGGING CARTON total %i\n", cartonTotal);
+
+  isWall[i] =abs(Scan1[i]-wall[i]);
+   printf("DeBUGGING isWall : %i\n", isWall[i]);
+    if (isWall[i]<=5){
+    isWall[i]=0;}
+else if (isWall[i]>5){
+isWall[i]=1;}
+printf("DeBUGGING isWall : %i\n", isWall[i]);
+wallTotal = accumulate(begin(isWall), end(isWall), 0, plus<int>());
+printf("DEBUGGING Wall total %i\n", wallTotal);
+
+;}
+printf("Im Free of the For Debug WallTotoal::  %i\n", wallTotal);
+printf("Im Free of the For Debug BoxTotoal::  %i\n", boxTotal);
+printf("Im Free of the For Debug cartonTotoal::  %i\n", cartonTotal);
+printShape();
+     
+        }
+void printShape(){
+    if(wallTotal == 0){
+     printf("We Have a wall\n");
+                   lcd.clear();
+        lcd.printString("Wall",0,2);
+        lcd.drawLine(20,0,20,5,1);
+        lcd.refresh();;}
+     else if(boxTotal=0){
+         printf("We Have Box\n");}
+         else;
+         printf("Not in the Database \n");}
\ No newline at end of file