Samenwerking Groep 12

Dependencies:   Encoder MODSERIAL HIDScope mbed

Foo

main.cpp

Committer:
ThomasBNL
Date:
2015-09-21
Revision:
17:6b91c3549301
Parent:
14:7603d7f1dbe9
Child:
18:dfdc44cbcb3b

File content as of revision 17:6b91c3549301:

#include "mbed.h"
#include "encoder.h"
#include "MODSERIAL.h"

//Motor 2
DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
PwmOut motor2speed(D5);
DigitalIn button(PTA4);
Encoder motor2(D13,D12);
MODSERIAL pc(USBTX,USBRX);
double reference = 2000;

int main()
{
    pc.baud(9600);
    motor2.setPosition(0);
    
    while(button = 0)
    
    while(true) {
    double  R = (reference - motor2.getPosition());
    pc.printf("error R = %d \r\n", R);

        if (R>1) {
            motor2direction = 1; //CW
            motor2speed = 0.5f;
            pc.printf("positie = %d \r\n", motor2.getPosition());
        } else    {
            motor2direction = 0; //CCW
            motor2speed = 0.5f;
            pc.printf("positie = %d \r\n", motor2.getPosition());
        }
    }
}