Samenwerking Groep 12

Dependencies:   Encoder MODSERIAL HIDScope mbed

Foo

main.cpp

Committer:
bscheltinga
Date:
2015-09-21
Revision:
14:7603d7f1dbe9
Parent:
10:e923f51f18c4
Child:
17:6b91c3549301

File content as of revision 14:7603d7f1dbe9:

#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);
    double  R = (reference - motor2.getPosition());
    pc.printf("error R=%d \r\n", R);

    while(true) {
        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());
        }
    }
}