encoder, HIDscope and movement

Dependencies:   Encoder HIDScope mbed

Fork of MovementandEncoder by Arun Raveenthiran

Committer:
arunr
Date:
Mon Oct 12 13:10:43 2015 +0000
Revision:
2:174885cd1665
Parent:
1:bac42065f837
Child:
3:ac0fe759170f
Motor draait nu, met correcte snelheid. Encoder werkt niet.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:0b39982f89a9 1 #include "mbed.h"
vsluiter 0:0b39982f89a9 2 #include "HIDScope.h"
vsluiter 0:0b39982f89a9 3 #include "encoder.h"
vsluiter 0:0b39982f89a9 4
vsluiter 0:0b39982f89a9 5 Encoder motor1(D13,D12);
vsluiter 0:0b39982f89a9 6 PwmOut led(D9);
vsluiter 0:0b39982f89a9 7 HIDScope scope(1);
vsluiter 0:0b39982f89a9 8
arunr 1:bac42065f837 9 DigitalOut motor_direction(D4);
arunr 1:bac42065f837 10 PwmOut motor_speed(D5);
arunr 1:bac42065f837 11
arunr 2:174885cd1665 12 DigitalIn button_1(PTC6); //counterclockwise
arunr 2:174885cd1665 13 DigitalIn button_2(PTA4); //clockwise
arunr 2:174885cd1665 14
arunr 2:174885cd1665 15 const int pressed = 0;
arunr 2:174885cd1665 16
arunr 2:174885cd1665 17
arunr 2:174885cd1665 18 void move_motor_ccw (){
arunr 2:174885cd1665 19 motor_direction = 0;
arunr 2:174885cd1665 20 motor_speed = 1;
arunr 2:174885cd1665 21 }
arunr 2:174885cd1665 22
arunr 2:174885cd1665 23 void move_motor_cw (){
arunr 2:174885cd1665 24 motor_direction = 1;
arunr 2:174885cd1665 25 motor_speed = 0.1;
arunr 2:174885cd1665 26 }
arunr 2:174885cd1665 27
vsluiter 0:0b39982f89a9 28 int main()
vsluiter 0:0b39982f89a9 29 {
arunr 2:174885cd1665 30 scope.set(0,motor1.getPosition());
arunr 2:174885cd1665 31
vsluiter 0:0b39982f89a9 32 while (true) {
arunr 2:174885cd1665 33
arunr 2:174885cd1665 34 if (button_1 == pressed){
arunr 2:174885cd1665 35 move_motor_cw ();
arunr 2:174885cd1665 36 }
arunr 2:174885cd1665 37 else if (button_2 == pressed){
arunr 2:174885cd1665 38 move_motor_ccw ();
arunr 2:174885cd1665 39 }
arunr 2:174885cd1665 40 else {
arunr 2:174885cd1665 41 motor_speed = 0;
arunr 2:174885cd1665 42 }
arunr 1:bac42065f837 43
vsluiter 0:0b39982f89a9 44 led.write(motor1.getPosition()/100.0);
vsluiter 0:0b39982f89a9 45 scope.send();
vsluiter 0:0b39982f89a9 46 wait(0.2f);
arunr 2:174885cd1665 47
vsluiter 0:0b39982f89a9 48 }
vsluiter 0:0b39982f89a9 49 }