encoder verwerkt

Dependencies:   MODSERIAL QEI mbed

Fork of motor_control by Floor Couwenberg

Committer:
daniQQue
Date:
Fri Sep 30 11:46:13 2016 +0000
Revision:
2:80753272d9e4
Parent:
1:e415c6eda278
Child:
3:a50f2ce05e1f
encoder included met forloops;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniQQue 2:80753272d9e4 1 #include "mbed.h" //standaard bieb mbed
daniQQue 2:80753272d9e4 2 #include "QEI.h" //bieb voor encoderfuncties in c++
daniQQue 2:80753272d9e4 3 #include "MODSERIAL.h" //bieb voor modserial
daniQQue 2:80753272d9e4 4 //alle ingangen definieren
daniQQue 2:80753272d9e4 5 DigitalIn encoder1A(D13);
daniQQue 2:80753272d9e4 6 DigitalIn encoder1B(D12);
daniQQue 2:80753272d9e4 7 DigitalIn button(D11);
daniQQue 2:80753272d9e4 8 DigitalOut led(D10);
daniQQue 2:80753272d9e4 9 DigitalOut motor1(D4);
daniQQue 2:80753272d9e4 10 PwmOut pwm_motor1(D5);
daniQQue 2:80753272d9e4 11 MODSERIAL pc(USBTX, USBRX);
FloorC 1:e415c6eda278 12
daniQQue 2:80753272d9e4 13 //constanten
daniQQue 2:80753272d9e4 14 const int CW = 0; //definitie rechtsom 'lage waarde'
daniQQue 2:80753272d9e4 15 const int CCW =2.5; //definitie linksom 'hoge waarde'
FloorC 0:8ed7e7bbc391 16
daniQQue 2:80753272d9e4 17 //programma
FloorC 1:e415c6eda278 18 int main ()
FloorC 0:8ed7e7bbc391 19 {
daniQQue 2:80753272d9e4 20 pc.baud(115200); //contact maken met computer
daniQQue 2:80753272d9e4 21 int counts;
daniQQue 2:80753272d9e4 22 while (knop==1){ //als knop is aan dan
daniQQue 2:80753272d9e4 23 led=1;
daniQQue 2:80753272d9e4 24 motor = CCW;
daniQQue 2:80753272d9e4 25 QEI Encoder(D12,D13,NC,32);
daniQQue 2:80753272d9e4 26 counts = Encoder.getPulses();
daniQQue 2:80753272d9e4 27 pc.printf("encoder counts %i", counts);
daniQQue 2:80753272d9e4 28
daniQQue 2:80753272d9e4 29 for (int a=0; a<5;a=a++){
daniQQue 2:80753272d9e4 30 pwm_motor =a;
daniQQue 2:80753272d9e4 31 wait(2.0f);
daniQQue 2:80753272d9e4 32 }
daniQQue 2:80753272d9e4 33
daniQQue 2:80753272d9e4 34 int a=0;
daniQQue 2:80753272d9e4 35 wait(1.0f);
daniQQue 2:80753272d9e4 36 motor=CW;
daniQQue 2:80753272d9e4 37 for (int a=1; a<5;a=a++){
daniQQue 2:80753272d9e4 38 pwm_motor= a;
daniQQue 2:80753272d9e4 39 wait(1.0f);
daniQQue 2:80753272d9e4 40 }
daniQQue 2:80753272d9e4 41 a=0;
daniQQue 2:80753272d9e4 42
daniQQue 2:80753272d9e4 43
FloorC 1:e415c6eda278 44 }
FloorC 1:e415c6eda278 45 }