hode pid broertje

Dependencies:   HIDScope QEI biquadFilter mbed

Revision:
0:edcdd09960f7
Child:
1:3d92e7ff3dda
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 15 10:39:56 2018 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+AnalogIn pot1(A2); // Controls potentiometer 1, which controls motor 1
+InterruptIn button1(D0);
+DigitalOut directionpin(D7);
+PwmOut pwmpin(D6);
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+void SetMotorSpeed1(){
+        float MotorSpeed1 = pot1; // Speed of the motor in rad/s
+        pc.printf("Speed of motor 1: %f rad/s. \n", MotorSpeed1);
+        if(pot1<=0.46f){
+            pwmpin = 0;
+            }
+        else{
+        pwmpin = fabs(pot1); // Outputs the value of potmeter 1, which is used as the velocity.
+        }
+}
+
+void Motor1Direction(){
+    directionpin = !directionpin;
+}
+
+int main() {
+    pwmpin.period_us(60);   // Set pwm period
+    button1.rise(&Motor1Direction); // if the button is pressed, change the direction
+    while (true) {
+        SetMotorSpeed1();
+    }
+}
\ No newline at end of file