statemachine

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

main.cpp

Committer:
boydmartherus
Date:
2019-09-23
Revision:
15:49f750d895d7
Parent:
14:4342436f9f4f

File content as of revision 15:49f750d895d7:

#include "mbed.h"
#include "MODSERIAL.h"
#include "FastPWM.h" 
#include "QEI.h" 
//#include "Motor.h" 

Serial pc(USBTX,USBRX);

AnalogIn pot(PTB2);
InterruptIn button(PTB3);

FastPWM motor(D5);
FastPWM led(PTA1);
DigitalOut direction(D4);

int pulses = 131;
QEI wheel (D13,D12,NC,pulses);

int richting;

void flip()
{
    richting=!richting;
}


int main()
{ 
    printf("Control with dial\n");
    button.rise(&flip);
    while(true)
        {
            if (richting == 1)
                {
                wait(0.05);
                printf("now forward");
                led.write(pot);
                motor.write(pot);
                wait(0.05);
                direction.write(richting);
                //printf("motor speeed is (%f)\n\r",pot.read());
                //printf("pulse number is (%i)\n\r",wheel.getPulses());
                }
            else
                {
                wait(0.05);
                printf("now reversing");
                led.write(1-pot);
                motor.write(pot);
                wait(0.05);
                direction.write(richting);
                //printf("motor speeed is (%f)\n\r",pot.read());
                //printf("pulse number is (%i)\n\r",wheel.getPulses());
                }
        }
}