Six crescent shaped legs

Dependencies:   mbed

Revision:
2:cf0147952fb9
Parent:
1:8b0322a353f4
Child:
3:2235787e78c4
--- a/main.cpp	Mon Mar 28 12:23:38 2016 +0000
+++ b/main.cpp	Tue Mar 29 12:03:14 2016 +0000
@@ -1,71 +1,32 @@
 #include "mbed.h"
-#include "time.h"
+#include "Motor.hpp"
+#include "Encoder.hpp"
 
-Timer timer;
-PwmOut mypwm(PB_0);
-DigitalOut dir1(PC_0);
-DigitalOut dir2(PC_1);
-InterruptIn encA(PA_0);
-//InterruptIn encB(PA_1);
 InterruptIn bt(USER_BUTTON);
-Serial pc(SERIAL_TX, SERIAL_RX);
+Serial pc(USBTX, USBRX);
+
+Motor m(PB_0, PC_0, PC_1);
+Encoder e(PA_0, PA_1);
 
-int iAeg = 0;
-//int iDir;
-//int iTime = 0;
-unsigned long long int iSum = 0;
-double dPwm = 0.2;
-double newPwm = dPwm;
-double miss = 0;
-double lastMiss = 0;
-double chPwm = 0;
-double totMiss = 0;
-double minPwm = 0.1;
-double maxPwm = 0.7;
-double dSpeed = 0.5;
+void rise()
+{
+    pc.printf("rise\n");
+    m.drive(0.1f);
+}
 
+void fall()
+{
+    pc.printf("fall\n");
+    m.drive(-0.1f);
+}
 
-/*int getDir(){
-    if ((dAeg/(double)iDir > 0.5){
-        return (1);}
-    else return 0;
-    }*/
-void start(){
-    timer.reset();
+int main()
+{
+    bt.rise(rise);
+    bt.fall(fall);
+    while(1)
+    {
+        pc.printf("%d\n", e.getCount());
+        wait(0.5);
     }
-/*void dir(){
-    iDir = timer.read_us();
-    }*/
-void stop(){
-    iAeg = timer.read_us();
-    //iDir = getDir();
-    }
-
-int main(){
-    timer.start();
-    encA.rise(&start);
-    encA.fall(&stop);
-    //encB.rise(&dir);
-    double real = (1-dSpeed)*1000;
-    mypwm.write(dPwm);
-    dir1 = 1;
-    dir2 = 0;
-    while(1){
-        if (iAeg != 0){
-                miss = iAeg - real;
-                totMiss = totMiss + miss;
-                chPwm = totMiss/200000;
-                if (chPwm > -0.0001 && chPwm < 0.0001) {
-                    pc.printf("%f,%f\n",totMiss,chPwm);}
-                newPwm = dPwm + chPwm;
-                if (newPwm < minPwm){
-                    newPwm = minPwm;
-                    }
-                else if (newPwm > maxPwm){
-                    newPwm = maxPwm;
-                    }
-                mypwm.write(newPwm);
-                iAeg = 0;
-            }
-        }
-    }
\ No newline at end of file
+}
\ No newline at end of file