Met kinematics

Dependencies:   MODSERIAL QEI mbed-dsp mbed

Fork of Motorcode by ProjectGroep23

main.cpp

Committer:
rachieldb
Date:
2018-10-01
Revision:
8:9b517db94f49
Parent:
7:e21056555296
Child:
9:466dff9ae128

File content as of revision 8:9b517db94f49:

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


DigitalOut ledr(LED_RED);
DigitalOut ledg(LED_GREEN);
DigitalOut ledb(LED_BLUE);

PwmOut  pwmpin(PTA2);
DigitalOut direct(PTB23);
AnalogIn pot1(A0);

QEI encoder(D12,D13,NC,32); 

InterruptIn  sw2(SW2);
InterruptIn  sw3(SW3);

MODSERIAL pc(USBTX, USBRX);


int main()
{
    ledr = 1;
    ledg = 1;
    ledb = 1;
    
    pc.printf("\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ~~~A$$De$troyer69~~~ \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n");
    
    pwmpin.period_us(60);
    pwmpin = 0;
  
    while (true)
    {
            float pot1_float = pot1.read();
            float pot1_motor = (pot1_float * 2.0f) - 1.0f;
            int mot1_direction = pot1_motor >= 0;
            pwmpin.write(fabs(pot1_motor));
            direct = mot1_direction;
            pc.printf("potmeter: %f, encoder: %i \r\n", pot1_motor, encoder.getPulses());
            wait(0.2f);
    }
}