encoder verwerkt
Dependencies: MODSERIAL QEI mbed
Fork of motor_control by
Diff: main.cpp
- Revision:
- 2:80753272d9e4
- Parent:
- 1:e415c6eda278
- Child:
- 3:a50f2ce05e1f
diff -r e415c6eda278 -r 80753272d9e4 main.cpp --- a/main.cpp Thu Sep 29 13:29:18 2016 +0000 +++ b/main.cpp Fri Sep 30 11:46:13 2016 +0000 @@ -1,20 +1,45 @@ -#include "mbed.h" - -DigitalOut motor(D4); -PwmOut pwm_motor(D5); -//DigitalIn switch3(SW3); +#include "mbed.h" //standaard bieb mbed +#include "QEI.h" //bieb voor encoderfuncties in c++ +#include "MODSERIAL.h" //bieb voor modserial +//alle ingangen definieren +DigitalIn encoder1A(D13); +DigitalIn encoder1B(D12); +DigitalIn button(D11); +DigitalOut led(D10); +DigitalOut motor1(D4); +PwmOut pwm_motor1(D5); +MODSERIAL pc(USBTX, USBRX); -Serial pc(USBTX, USBRX); +//constanten +const int CW = 0; //definitie rechtsom 'lage waarde' +const int CCW =2.5; //definitie linksom 'hoge waarde' -int CW = 0; -int CCW = 1; - +//programma int main () { - while (true){ - motor = CW; - pwm_motor = 0.5; - - + pc.baud(115200); //contact maken met computer + int counts; + while (knop==1){ //als knop is aan dan + led=1; + motor = CCW; + QEI Encoder(D12,D13,NC,32); + counts = Encoder.getPulses(); + pc.printf("encoder counts %i", counts); + + for (int a=0; a<5;a=a++){ + pwm_motor =a; + wait(2.0f); + } + + int a=0; + wait(1.0f); + motor=CW; + for (int a=1; a<5;a=a++){ + pwm_motor= a; + wait(1.0f); + } + a=0; + + } } \ No newline at end of file