statemachine

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
17:3751c2c685ca
Parent:
16:0ff43ed4d259
Child:
18:3de4412d8b63
--- a/main.cpp	Mon Sep 23 10:09:32 2019 +0000
+++ b/main.cpp	Mon Sep 23 12:36:08 2019 +0000
@@ -1,32 +1,46 @@
 #include "mbed.h"
 #include "MODSERIAL.h"
-#include "FastPWM.h" 
-#include "QEI.h" 
+#include "FastPWM.h"
+#include "QEI.h"
 
 Serial pc(USBTX,USBRX);
 
-AnalogIn pot(PTB2);
-InteruptIn button(PTB3)
-
+// functies aan PINs toevoegen
 FastPWM led(PTA1);
 FastPWM motor(D5);
-DigitalOut direction(D4);
+AnalogIn pot(PTB2);
+InterruptIn button(PTB3);
 
+// timer opzetten = ticker
+Ticker ticker;
+
+// opzetten van hoekbepaling
 int pulses = 4200;
 QEI wheel (D13,D12,NC,pulses);
 
+// aparte functies
+// functie hoekbepaling
+void hoek_bepaling()
+{
+    wheel.getPulses();
+}
+
+//functie motor aansturen met pot
+void motor_running()
+{
+    motor.write(pot);
+    led.write(pot);
+}
+
+// functie print output
+
+void main_loop()
+{
+    hoek_bepaling();
+    motor_running();
+}
 int main()
 { 
-    printf("Control with dial\n");
-        while(true)
-            {
-                wait(0.1);
-                printf("motor speeed is (%f)\n\r",pot.read());
-                wait(0.1);
-                led.write(pot);
-                wait(0.1);
-                motor.write(pot);
-                wait(0.1);
-                printf("pulse number is (%i)\n\r",wheel.getPulses());
-            }
+    ticker.attach(&mainloop, 0.001f);
+    while(true){};  
 }
\ No newline at end of file