Button_encoder_DCmotor
Dependencies: MODSERIAL QEI mbed
main.cpp@1:18f75ab86b7a, 2016-10-03 (annotated)
- Committer:
- 11i
- Date:
- Mon Oct 03 07:25:07 2016 +0000
- Revision:
- 1:18f75ab86b7a
- Parent:
- 0:8794c0729d84
Button_encoder_DCmotors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
11i | 0:8794c0729d84 | 1 | #include "QEI.h" |
11i | 0:8794c0729d84 | 2 | #include "mbed.h" |
11i | 0:8794c0729d84 | 3 | #include "MODSERIAL.h" |
11i | 0:8794c0729d84 | 4 | |
11i | 0:8794c0729d84 | 5 | // Definiëren van alle poorten |
11i | 0:8794c0729d84 | 6 | |
11i | 0:8794c0729d84 | 7 | DigitalIn encoder1A (D13); //Channel A van Encoder 1 |
11i | 0:8794c0729d84 | 8 | DigitalIn encoder1B (D12); //Channel B van Encoder 1 |
11i | 0:8794c0729d84 | 9 | DigitalIn button_cw (D11); //Clockwise rotation |
11i | 0:8794c0729d84 | 10 | DigitalIn button_ccw (D9); //Counterclockwise rotation |
11i | 0:8794c0729d84 | 11 | DigitalOut Ledcw (D10); |
11i | 0:8794c0729d84 | 12 | DigitalOut Ledccw (D2); |
11i | 0:8794c0729d84 | 13 | DigitalOut motor1 (D4); |
11i | 0:8794c0729d84 | 14 | PwmOut pwm_motor1 (D5); |
11i | 0:8794c0729d84 | 15 | MODSERIAL pc(USBTX, USBRX); |
11i | 0:8794c0729d84 | 16 | |
11i | 0:8794c0729d84 | 17 | //constanten |
11i | 0:8794c0729d84 | 18 | const in CW = 2.5; //Clockwise 'lage waarde' |
11i | 0:8794c0729d84 | 19 | const in CCW= 0; // Counterclockwise 'hoge waarde |
11i | 0:8794c0729d84 | 20 | |
11i | 0:8794c0729d84 | 21 | int main() { |
11i | 0:8794c0729d84 | 22 | |
11i | 0:8794c0729d84 | 23 | pc.baud(115200); //snelheid contact computer |
11i | 0:8794c0729d84 | 24 | QEI Encoder(D12, D13, NC, 32); //maakt de encoder aan |
11i | 0:8794c0729d84 | 25 | int counts; |
11i | 0:8794c0729d84 | 26 | |
11i | 0:8794c0729d84 | 27 | while(true){ |
11i | 0:8794c0729d84 | 28 | if (button_cw==0){ |
11i | 0:8794c0729d84 | 29 | ledcw=1; |
11i | 0:8794c0729d84 | 30 | motor1= CW; |
11i | 0:8794c0729d84 | 31 | pwm_motor1=2.5; |
11i | 0:8794c0729d84 | 32 | counts = Encoder.getPulses(); |
11i | 0:8794c0729d84 | 33 | pc.printf("Encoder counts: %i \r\n", counts); |
11i | 0:8794c0729d84 | 34 | } |
11i | 0:8794c0729d84 | 35 | else if (button_ccw==0) { |
11i | 0:8794c0729d84 | 36 | ledccw=1; |
11i | 0:8794c0729d84 | 37 | motor1= CCW; |
11i | 0:8794c0729d84 | 38 | pwm_motor1=2.5; |
11i | 0:8794c0729d84 | 39 | counts = Encoder.getPulses(); |
11i | 0:8794c0729d84 | 40 | pc.printf("Encoder counts: %i \r\n", counts); |
11i | 0:8794c0729d84 | 41 | } |
11i | 0:8794c0729d84 | 42 | else{ |
11i | 0:8794c0729d84 | 43 | ledcw=0; |
11i | 0:8794c0729d84 | 44 | ledccw=0; |
11i | 0:8794c0729d84 | 45 | pwm_motor1=0; |
11i | 0:8794c0729d84 | 46 | } |
11i | 0:8794c0729d84 | 47 | } |
11i | 0:8794c0729d84 | 48 | |
11i | 0:8794c0729d84 | 49 | } |
11i | 0:8794c0729d84 | 50 | |
11i | 0:8794c0729d84 | 51 |