Samenwerking Groep 12

Dependencies:   Encoder MODSERIAL HIDScope mbed

Foo

main.cpp

Committer:
ThomasBNL
Date:
2015-09-21
Revision:
18:dfdc44cbcb3b
Parent:
17:6b91c3549301

File content as of revision 18:dfdc44cbcb3b:

#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.read()< 0.5) 
    {motor2direction = 1;
    motor2speed = 0.5f;}
    
    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());
        }
    }
}