Button_encoder_DCmotor
Dependencies: MODSERIAL QEI mbed
Diff: main.cpp
- Revision:
- 0:8794c0729d84
diff -r 000000000000 -r 8794c0729d84 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Oct 02 19:27:15 2016 +0000 @@ -0,0 +1,51 @@ +#include "QEI.h" +#include "mbed.h" +#include "MODSERIAL.h" + +// Definiëren van alle poorten + +DigitalIn encoder1A (D13); //Channel A van Encoder 1 +DigitalIn encoder1B (D12); //Channel B van Encoder 1 +DigitalIn button_cw (D11); //Clockwise rotation +DigitalIn button_ccw (D9); //Counterclockwise rotation +DigitalOut Ledcw (D10); +DigitalOut Ledccw (D2); +DigitalOut motor1 (D4); +PwmOut pwm_motor1 (D5); +MODSERIAL pc(USBTX, USBRX); + + //constanten + const in CW = 2.5; //Clockwise 'lage waarde' + const in CCW= 0; // Counterclockwise 'hoge waarde + +int main() { + + pc.baud(115200); //snelheid contact computer + QEI Encoder(D12, D13, NC, 32); //maakt de encoder aan + int counts; + + while(true){ + if (button_cw==0){ + ledcw=1; + motor1= CW; + pwm_motor1=2.5; + counts = Encoder.getPulses(); + pc.printf("Encoder counts: %i \r\n", counts); + } + else if (button_ccw==0) { + ledccw=1; + motor1= CCW; + pwm_motor1=2.5; + counts = Encoder.getPulses(); + pc.printf("Encoder counts: %i \r\n", counts); + } + else{ + ledcw=0; + ledccw=0; + pwm_motor1=0; + } + } + +} + + \ No newline at end of file