First Draft, serial print change based on distance

Revision:
3:0b0fbddb6f51
Parent:
2:3ace5b4ae9a7
Child:
4:77500a7f951d
diff -r 3ace5b4ae9a7 -r 0b0fbddb6f51 main.cpp
--- a/main.cpp	Fri Jan 21 13:51:49 2022 +0000
+++ b/main.cpp	Fri Jan 21 14:25:05 2022 +0000
@@ -1,6 +1,9 @@
 #include "mbed.h"
 #include "ultrasonic.h"
 #include "N5110.h"
+// added R and L buttons presses in so that the user has to press when they are ready to rotate object and in which direction
+DigitalIn L(PTB18);
+DigitalIn R(PTB3);
 
 // LEDs on PCB to be connected (1 to 6) - active-low 0 = on and 1 = off
 BusOut output(PTA1,PTA2,PTC2,PTC3,PTC4,PTD3);
@@ -20,7 +23,8 @@
 {
     // set inital state 
     int state = 0;
-    
+    R.mode(PullDown);
+    L.mode(PullDown);
     mu.startUpdates();//start mesuring the distance
     while(1)
     {
@@ -28,22 +32,46 @@
         // check which state we are in and see which the next state should be
         switch(state) {
             case 0:
-                state = 1;
+            if (R == 1){
+                state = 1;}
+            else if (L == 1){
+                state = 5;}
+            else state = 0;
                 break;
             case 1:
-                state = 2;
+            if (R == 1){
+                state = 2;}
+            else if (L == 1){
+                state = 0;}
+            else state = 1;
                 break;
             case 2:
-                state = 3;
+            if (R == 1){
+                state = 3;}
+            else if (L == 1){
+                state = 1;}
+            else state = 2;
                 break;
             case 3:
-                state = 4;
+            if (R == 1){
+                state = 4;}
+            else if (L == 1){
+                state = 2;}
+            else state = 3;
                 break;
             case 4:
-                state = 5;
+            if (R == 1){
+                state = 5;}
+            else if (L == 1){
+                state = 3;}
+            else state = 4;
                 break;
             case 5:
-                state = 0;
+            if (R == 1){
+                state = 0;}
+            else if (L == 1){
+                state = 4;}
+            else state = 5;
                 break;
             default:
                 error("Invalid state");  //invalid state - call error routine