Carlmaykel Orman / Mbed 2 deprecated NR_method_1

Dependencies:   HIDScope QEI biquadFilter mbed

Fork of NR_method by Thijs Rakels

Revision:
11:b1ad257e5647
Parent:
10:86c810be889a
Child:
12:771f3c73fe24
diff -r 86c810be889a -r b1ad257e5647 NR_method_1.cpp
--- a/NR_method_1.cpp	Thu Nov 01 20:05:45 2018 +0000
+++ b/NR_method_1.cpp	Thu Nov 01 20:50:14 2018 +0000
@@ -23,7 +23,7 @@
 DigitalOut M2(D7); // direction of motor 2
 
 // hidscope
-HIDScope    scope( 4 ); // 4 to check the different 
+HIDScope    scope( 4 ); // 4 to check the different
 
 // tickers
 Ticker sample_timer;
@@ -75,7 +75,8 @@
 double emgFiltered3;
 double emgFiltered23;
 bool dir = true;
-
+char lett;
+int num;
 // filtering
 //filter coeffiecents
 // highpass
@@ -139,11 +140,11 @@
         Led2 = 0;
         i = 0;
         Cxx =x1;
-        pc.printf("Moving in the x direction\n\r");
+        //pc.printf("Moving in the x direction\n\r");
         if (dir == true) {
             if(x1 > -46.3) {
                 x1 = x1-4.2;
- 
+
 
             } else if ( x1 <= -46.3) {
                 x1 =-17;
@@ -159,6 +160,8 @@
             } else {
             }
         }
+
+
     }
 }
 
@@ -391,7 +394,7 @@
     wait(0.1);
     PMW2.write(0);
     count3 = Enc2.getPulses();
-    
+
     setCalibration();
     pc.printf("Calibration is done\r\n");
     pc.printf("Please press button SW3\n\r");
@@ -405,7 +408,7 @@
     Xold[0][0] = X0[0][0];
     Xold[1][0] = X0[1][0];
     initializeren();
-    pc.printf("Initialization step done. Enjoy your game!\n\r");
+    pc.printf("Initialization step done\n\r");
     x1 = Cxx;
     y1= Cyy;
     bqc.add( &bq1 ).add( &bq2 );
@@ -436,7 +439,66 @@
                 i++;
             }
 
+            float x = (abs(x1+17)/4.2);
+            float y = (abs(y1 -3)/4.2);
 
+            switch ((int)y) {
+                case 0:
+                    lett = 'A';
+                    break;
+                case 1:
+                    lett = 'B';
+                    break;
+                case 2:
+                    lett = 'C';
+                    break;
+                case 3:
+                    lett = 'D';
+                    break;
+                case 4:
+                    lett = 'E';
+                    break;
+                case 5:
+                    lett = 'F';
+                    break;
+                case 6:
+                    lett = 'G';
+                    break;
+                case 7:
+                    lett = 'H';
+                    break;
+                default:
+                    break;
+            }
+            switch ((int)x) {
+                case 0:
+                    num =1;
+                    break;
+                case 1:
+                    num =2;
+                    break;
+                case 2:
+                    num =3;
+                    break;
+                case 3:
+                    num =4;
+                    break;
+                case 4:
+                    num =5;
+                    break;
+                case 5:
+                    num =6;
+                    break;
+                case 6:
+                    num =7;
+                    break;
+                case 7:
+                    num =8;
+                    break;
+                default:
+                    break;
+            }
+            pc.printf("%c %i\r\n",lett,num);
             sw2.fall(change);
             Position1x(emgFiltered3);
             Position1y(emgFiltered23);