hode pid broertje

Dependencies:   HIDScope QEI biquadFilter mbed

main.cpp

Committer:
ekiliptiay
Date:
2018-10-15
Revision:
0:edcdd09960f7
Child:
1:3d92e7ff3dda

File content as of revision 0:edcdd09960f7:

#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();
    }
}