Draai motor bij indrukken van button, in verschillende snelheden.
Dependencies: Encoder HIDScope mbed
Fork of DemoHidScopeEncoder by
Diff: main.cpp
- Revision:
- 2:174885cd1665
- Parent:
- 1:bac42065f837
diff -r bac42065f837 -r 174885cd1665 main.cpp --- a/main.cpp Wed Oct 07 13:18:35 2015 +0000 +++ b/main.cpp Mon Oct 12 13:10:43 2015 +0000 @@ -9,16 +9,41 @@ DigitalOut motor_direction(D4); PwmOut motor_speed(D5); +DigitalIn button_1(PTC6); //counterclockwise +DigitalIn button_2(PTA4); //clockwise + +const int pressed = 0; + + +void move_motor_ccw (){ + motor_direction = 0; + motor_speed = 1; + } + +void move_motor_cw (){ + motor_direction = 1; + motor_speed = 0.1; + } + int main() { - motor_direction = 1; - motor_speed = 0.5; - + scope.set(0,motor1.getPosition()); + while (true) { + + if (button_1 == pressed){ + move_motor_cw (); + } + else if (button_2 == pressed){ + move_motor_ccw (); + } + else { + motor_speed = 0; + } - scope.set(0,motor1.getPosition()); led.write(motor1.getPosition()/100.0); scope.send(); wait(0.2f); + } } \ No newline at end of file