encoder verwerkt
Dependencies: MODSERIAL QEI mbed
Fork of motor_control by
main.cpp@5:bb97950558bd, 2016-09-30 (annotated)
- Committer:
- daniQQue
- Date:
- Fri Sep 30 12:01:06 2016 +0000
- Revision:
- 5:bb97950558bd
- Parent:
- 4:d39f84608204
- Child:
- 6:93a7d2989024
nieuwe poorten aangesloten(Verkeerde motor en encoder combi);
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:d39f84608204 | 21 | volatile int counts; |
daniQQue | 4:d39f84608204 | 22 | while(true) |
daniQQue | 4:d39f84608204 | 23 | { |
daniQQue | 5:bb97950558bd | 24 | if (button==0) |
daniQQue | 4:d39f84608204 | 25 | { //als knop is aan dan |
daniQQue | 2:80753272d9e4 | 26 | led=1; |
daniQQue | 4:d39f84608204 | 27 | motor1= CCW; |
daniQQue | 3:a50f2ce05e1f | 28 | pwm_motor1=2.5; |
daniQQue | 4:d39f84608204 | 29 | QEI Encoder(D12,D13,NC,64); |
daniQQue | 2:80753272d9e4 | 30 | counts = Encoder.getPulses(); |
daniQQue | 5:bb97950558bd | 31 | pc.printf("encoder counts %i/r/n", counts); |
daniQQue | 2:80753272d9e4 | 32 | |
daniQQue | 4:d39f84608204 | 33 | } |
daniQQue | 4:d39f84608204 | 34 | else{ |
daniQQue | 4:d39f84608204 | 35 | led=!led; |
daniQQue | 4:d39f84608204 | 36 | pwm_motor1=0; |
daniQQue | 4:d39f84608204 | 37 | } |
daniQQue | 3:a50f2ce05e1f | 38 | } |
FloorC | 1:e415c6eda278 | 39 | } |