Board Garudago >> Motor6 --> 1 || Motor2 --> 2 key board: A S --> control pwm1 K L --> control pwm2

Dependencies:   Motor mbed

Board Garudago (Motor6 ==> 1 || Motor2 ==> 2)

key board

  • A S : control pwm1
  • K L : control pwm2
Revision:
0:266cc01fc2c3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 10 13:19:25 2016 +0000
@@ -0,0 +1,48 @@
+// Library
+#include "mbed.h"
+#include "Motor.h"
+
+// Deklarasi pin
+Motor motor1 (PB_9, PA_12, PC_5);
+Motor motor2 (PA_11, PA_6, PC_6);
+
+int main (void){
+    Serial pc(USBTX,USBRX);
+    pc.baud(9600);
+    pc.readable();
+    float pwm1=0.1;
+    float pwm2=0.1;
+    
+    while(1){
+        char val = pc.getc();
+        switch (val) {
+            case 'a' :{
+                pwm1 = pwm1+0.05;
+            }
+            break; 
+            case 's' :{
+                pwm1 = pwm1-0.05;
+            }
+            break;
+            case 'k' :{
+                pwm2 = pwm2+0.05;
+            }
+            break;
+            case 'l' :{
+                pwm2 = pwm2-0.05;
+            }
+            break;
+        }
+        if (pwm1 <= 0.1){ 
+            pwm1 = 0.1;
+        }
+        if (pwm2 <= 0.1){ 
+            pwm2 = 0.1; 
+        }
+        
+        motor1.speed(pwm1);
+        motor2.speed(pwm2);
+        wait_ms(5);
+        pc.printf ("pwm1 = %.5f      pwm2 = %.5f\n", pwm1, pwm2);
+    }
+}
\ No newline at end of file