Alles in 1

Dependencies:   Encoder HIDScope MODSERIAL QEI mbed

Fork of RoboBird3 by Fernon Eijkhoudt

main.cpp

Committer:
Fernon
Date:
2015-09-28
Revision:
6:cf20f04dbab4
Parent:
5:d47e6a96256b
Child:
7:2042e359bfc3

File content as of revision 6:cf20f04dbab4:

#include "mbed.h"
#include "QEI.h"
#include "math.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;
Ticker PC;

double z=0;
const double twopi = 6.2831853071795;
const double pi = pi/2;
int Pulses;
double Rotatie;
double Rotatietwopi;

void readpot()
{
    z = PotMeter.read();
}

void print()
{
    //pc.printf ("Potmeter = %f\n", z); // het weergeven van de waarde waar z (PotMeter) op dat moment is
    //pc.printf ("Rotatie = %f [pi radialen] \n", Rotatietwopi);
}

int main()
{
    pc.baud(115200);
    PowerMotor.write(0);
    Pot.attach(readpot,0.1); // Deze ticker moet de waarde uitlezen van de PotMeter 10 keer per seconde
    //PC.attach(print,0.5);
    while (true) {
        PowerMotor.write(z);
      //  Pulses = Encoder.getPulses();
//        Rotatie = (Pulses*twopi)/4192;
//        Rotatietwopi = fmod(Rotatie,twopi);
    }
}