Alles in 1

Dependencies:   Encoder HIDScope MODSERIAL QEI mbed

Fork of RoboBird3 by Fernon Eijkhoudt

main.cpp

Committer:
Fernon
Date:
2015-09-28
Revision:
2:f0e9ffc5df09
Parent:
1:bb11e38dda43
Child:
3:af3f0ed8c99e

File content as of revision 2:f0e9ffc5df09:

#include "mbed.h"
#include "QEI.h"

DigitalOut Direction(D4); //1 = CCW - 0 = CW
PwmOut PowerMotor(D5); //van 0 tot 1
AnalogIn PotMeter(A1);
QEI Encoder(D13,D12,NC,32,QEI::X2_ENCODING); //Encoder
Serial pc(USBTX, USBRX);
Ticker Pot;

const double pi = 3.14159265359;
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) {
        Pulses = Encoder.getPulses();
        Rotatie = (Pulses*2*pi)/4192;
        pc.printf ("Potmeter = %f\n", z);
        pc.printf ("Rotatie = %f [radialen] \n", Rotatie);
    }
}