Luuk Lomillos Rozeboom / Mbed 2 deprecated RobotControlFinal

Dependencies:   HIDScope MODSERIAL QEI biquadFilter mbed

Revision:
0:1b8a08e9a66c
Child:
1:14b685c3abbd
diff -r 000000000000 -r 1b8a08e9a66c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Oct 07 20:46:58 2017 +0000
@@ -0,0 +1,107 @@
+#include "mbed.h"
+//#include "QEI.h"
+#include "MODSERIAL.h"
+//#include "HIDScope.h"
+
+
+Serial pc (USBTX,USBRX);
+//PwmOut Motor1Vel(D6);            //motor 1 velocity control
+//DigitalOut Motor1Dir(D7);        //motor 1 direction
+//PwmOut Motor2Vel(D5);            //motor 2 velocity control
+//DigitalOut Motor2Dir(D4);        //motor 2 direction
+DigitalOut led1(D8);
+DigitalOut led2(D9);
+AnalogIn emgx(A0);
+AnalogIn emgy(A1);
+//DigitalOut ledb(LED1);
+
+Ticker switch_tick;
+
+float limitx =3, limity = 3, positionx = 1, positiony = 1;
+
+int i = 0;                         //counter to go back to initial position if there is no activity
+
+void movex()
+{
+    led1 = 1;
+}
+void movey()
+{
+    led2 = 1;    
+}
+void movexy()
+{
+    led2 = 1;
+    led1 = 1;
+}
+void initialPosition()
+{
+    led2 = 0;
+    led1 = 0;
+}
+int choosecase(float emgx, float emgy)
+{
+    int a = 0;
+    if (emgx > 0 && emgy == 0)
+    {
+        a = 1;
+        i = 0;
+    }
+    else if (emgx == 0 && emgy > 0)
+    {
+        a = 2;
+        i = 0;
+    }
+    else if (emgx > 0 && emgy > 0)
+    {
+        a = 3;
+        i = 0;
+    }
+    else if (positionx >= limitx || positiony >= limity)
+    {
+        a = 4;
+        i = 0;
+    }
+    else if (i > 199)
+    {
+        a = 4;
+        i = 0;
+    }
+    else 
+    {
+        i++;
+    }
+    pc.printf("emgx: %f  emgy: %f \r\n",emgx,emgy);
+    return a;
+
+}
+void selectcase()
+{
+    int switchcons = choosecase(emgx,emgy);
+    switch(switchcons)
+    {
+        case 1:
+            movex();
+            break;
+        case 2:
+            movey();
+            break;
+        case 3:
+            movexy();
+            break;
+        case 4:
+            initialPosition();
+            break;
+        default:
+            break;
+    }
+    pc.printf("Chosen case: %d \r\n",switchcons);
+}
+main()
+{
+    pc.baud(115200);
+    switch_tick.attach(&selectcase,0.01);
+    while (true) {
+
+    }
+}
\ No newline at end of file