6.3 Motor mittels Tasten vor-, rückwärts, Stop laufen lassen und Poti benützen um die Geschwindigkeit einzustellen.

Dependencies:   mbed

Fork of 06-08-Uebung by th.iotkit1.ch

Revision:
2:48400c45778c
Parent:
1:128f2b08a419
diff -r 128f2b08a419 -r 48400c45778c main.cpp
--- a/main.cpp	Wed Apr 29 18:27:11 2015 +0000
+++ b/main.cpp	Mon Aug 10 16:07:58 2015 +0000
@@ -13,17 +13,21 @@
 
 // Motor an M01
 Motor m1(D3, D2, D4); // PWM, Vorwaerts, Rueckwarts
+// Fahrrichtung 1 = vorwaerts, -1 = rueckwaerts
+int dir = 1;
 
 int main()
 {
     while (true) 
     {
         if  ( button1 == 0 && button2 == 0 )
-            m1.speed( 0.0f );
+            dir = 0;
         else if ( button1 == 0 )
-            m1.speed( poti );
+            dir = 1;
         else if ( button2 == 0 )
-            m1.speed( poti * -1.0f );
+            dir = -1;
+            
+        m1.speed( poti * dir );
         wait(0.2f);
     }
 }
\ No newline at end of file