test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
NT32
Date:
Thu Jan 08 04:30:38 2015 +0000
Parent:
0:035867391bd5
Commit message:
???????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 035867391bd5 -r e9c99931de4f main.cpp
--- a/main.cpp	Tue Sep 16 04:47:40 2014 +0000
+++ b/main.cpp	Thu Jan 08 04:30:38 2015 +0000
@@ -1,13 +1,48 @@
 #include "mbed.h"
 
-DigitalIn   sw(P0_1, PullUp);
-DigitalOut  led(P1_28);
+#define STOP    0
+#define CW      1
+#define CCW     2
+ 
+Serial pc(dp16, dp15); // tx, rx
+
+PwmOut pincw(dp1), pinccw(dp2);
 
-int main(){
-    while(1){
-        while(sw == 0){
-            led = 1;
+int main() {
+    char cmd[64];
+    int rpm, pulsewidth, waittime, rounddirection = STOP;
+    pc.baud(115200);
+    pincw.write(0);
+    pinccw.write(0);
+    pincw.period_us(1500);
+    while(1) {
+        pc.scanf("%s", cmd);
+        pc.scanf("%d", &rpm);
+        pulsewidth = 1000000 / (rpm * 720 / 60);
+        if(strncmp(cmd,"CW", 2) == 0){
+            pinccw.write(1);
+            wait_us(200);
+            pincw.period_us(pulsewidth);
+            pincw.write(0.5);
+            rounddirection = CW;
+            pc.printf("OK\n");
+        }else if(strncmp(cmd,"CCW", 3) == 0){
+            pincw.write(1);
+            wait_us(200);
+            pinccw.period_us(pulsewidth);
+            pinccw.write(0.5);
+            rounddirection = CCW;
+            pc.printf("OK\n");
+        }else if(strncmp(cmd,"STOP", 4) == 0){
+            pinccw.write(1);
+            pincw.write(1);
+            rounddirection = STOP;
+            pc.printf("OK\n");
+        }else{
+            pinccw.write(1);
+            pincw.write(1);
+            rounddirection = STOP;
+            pc.printf("NG\n");
         }
-        led = 0;
     }
 }
diff -r 035867391bd5 -r e9c99931de4f mbed.bld
--- a/mbed.bld	Tue Sep 16 04:47:40 2014 +0000
+++ b/mbed.bld	Thu Jan 08 04:30:38 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file