Alles in 1

Dependencies:   Encoder HIDScope MODSERIAL QEI mbed

Fork of RoboBird3 by Fernon Eijkhoudt

Revision:
2:f0e9ffc5df09
Parent:
1:bb11e38dda43
Child:
3:af3f0ed8c99e
--- a/main.cpp	Wed Sep 23 12:19:33 2015 +0000
+++ b/main.cpp	Mon Sep 28 09:39:19 2015 +0000
@@ -6,28 +6,27 @@
 AnalogIn PotMeter(A1);
 QEI Encoder(D13,D12,NC,32,QEI::X2_ENCODING); //Encoder
 Serial pc(USBTX, USBRX);
+Ticker Pot;
 
-double P;
 const double pi = 3.14159265359;
-int Pulses; 
+int Pulses;
+double Rotatie;
+double z; 
+
+void readpot (double& z)
+{
+    z = PotMeter.read();
+}
 
 int main()
 {
+    pc.baud(115200);
+    PowerMotor.write(0);
+    Pot.attach(&readpot,&z,0.1);
     while (true) {
-        pc.baud(115200);
-        for (int n = 0; n < 2; n++) {
-            //P = PotMeter.read();
-            //pc.printf('P = %f/n', P);
-            Pulses = Encoder.getPulses();
-            pc.printf ("Pulses = %i", Pulses);
-            //  pc.printf ("K = %i \n", K);
-            Direction.write(0);
-            PowerMotor.write(0.5);
-            wait (1);
-            Direction.write(1);
-            wait (1);
-        }
-        PowerMotor.write(0);
-        return (0);
+        Pulses = Encoder.getPulses();
+        Rotatie = (Pulses*2*pi)/4192;
+        pc.printf ("Potmeter = %f\n", z);
+        pc.printf ("Rotatie = %f [radialen] \n", Rotatie);
     }
-}
\ No newline at end of file
+}