Draai motor bij indrukken van button, in verschillende snelheden.

Dependencies:   Encoder HIDScope mbed

Fork of DemoHidScopeEncoder by First Last

Files at this revision

API Documentation at this revision

Comitter:
arunr
Date:
Mon Oct 12 13:10:43 2015 +0000
Parent:
1:bac42065f837
Commit message:
Motor draait nu, met correcte snelheid. Encoder werkt niet.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
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