m3piに距離センサーを接続したときのテストプログラム

Dependencies:   mbed m3pi

Revision:
0:1c32a3ae67e1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 23 14:15:24 2011 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "m3pi.h"
+
+m3pi m3pi;
+
+AnalogIn ain(p20);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+int main() {
+
+    m3pi.locate(0,1);
+    m3pi.printf("LO World");
+
+    wait(2.0);
+    
+    for (int i = 0; i < 30; i++) {
+        m3pi.forward(0.1);
+        wait(0.5);
+        //         
+        led1 = (ain > 0.2) ? 1 : 0;
+        led2 = (ain > 0.4) ? 1 : 0;
+        led3 = (ain > 0.6) ? 1 : 0;
+        led4 = (ain > 0.8) ? 1 : 0;
+        
+        if (ain > 0.8) {
+            m3pi.backward(0.1);
+            wait(0.5);
+            m3pi.left(0.1);
+            wait(0.5);
+        }
+    }
+
+    m3pi.stop();       
+}
\ No newline at end of file