koubou no program death.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kambara1415
Date:
Fri Aug 28 05:04:23 2015 +0000
Commit message:
koubou no prog.

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 000000000000 -r e814f5861f7c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 28 05:04:23 2015 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+Ticker serial_time;
+DigitalIn encoderA(p19);
+DigitalIn encoderB(p18);
+
+int AB = 0;
+int pre_AB = 0;
+int count = 0;
+double deg = 0;
+
+void output(){
+ pc.printf("count = %d\ndistance = %.1lf\nAB = %d", count, deg, AB);
+ }
+ 
+int main() {
+    serial_time.attach(&output, 1.0);
+    while(1) {
+        AB = 00;
+        if(encoderA) AB += 10;
+        if(encoderB) AB += 01;
+        
+        if(AB == 00){
+            if(pre_AB == 10)    count++;
+            if(pre_AB == 01)    count--;
+        }
+        if(AB == 01){
+            if(pre_AB == 00)    count++;
+            if(pre_AB == 11)    count--;
+        }
+        if(AB == 10){
+            if(pre_AB == 11)    count++;
+            if(pre_AB == 00)    count--;
+        }
+        if(AB == 11){
+            if(pre_AB == 01)    count++;
+            if(pre_AB == 10)    count--;
+        }
+        deg = (double)count * 0.25;
+        pre_AB = AB;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r e814f5861f7c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 28 05:04:23 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file