encoder verwerkt
Dependencies: MODSERIAL QEI mbed
Fork of motor_control by
main.cpp@3:a50f2ce05e1f, 2016-09-30 (annotated)
- Committer:
- daniQQue
- Date:
- Fri Sep 30 11:48:01 2016 +0000
- Revision:
- 3:a50f2ce05e1f
- Parent:
- 2:80753272d9e4
- Child:
- 4:d39f84608204
poging encoder zonder for loops!!
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 | 2:80753272d9e4 | 21 | int counts; |
daniQQue | 3:a50f2ce05e1f | 22 | while (knop==1) |
daniQQue | 3:a50f2ce05e1f | 23 | { //als knop is aan dan |
daniQQue | 2:80753272d9e4 | 24 | led=1; |
daniQQue | 2:80753272d9e4 | 25 | motor = CCW; |
daniQQue | 3:a50f2ce05e1f | 26 | pwm_motor1=2.5; |
daniQQue | 2:80753272d9e4 | 27 | QEI Encoder(D12,D13,NC,32); |
daniQQue | 2:80753272d9e4 | 28 | counts = Encoder.getPulses(); |
daniQQue | 3:a50f2ce05e1f | 29 | pc.printf("encoder counts %i", counts); |
daniQQue | 2:80753272d9e4 | 30 | |
daniQQue | 3:a50f2ce05e1f | 31 | } |
FloorC | 1:e415c6eda278 | 32 | } |