2つのanalogスティックのanalog値をserial通信で送信しLEDをpwm制御するプログラムの送信側。受信側とセットで使えます。

Dependencies:   mbed

※解決策思いつかず。放置済み。※

Files at this revision

API Documentation at this revision

Comitter:
eil4nyqn
Date:
Sun Dec 21 06:34:09 2014 +0000
Commit message:
www;

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Dec 21 06:34:09 2014 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+
+AnalogIn stick[] = {p20,p19};
+Serial pc(USBTX,USBRX);
+Serial mc(p13,p14);
+PwmOut testled[] = {LED1,LED2,LED3,LED4};
+
+int main() {
+    double signal,signal2,signal3,signal4,analog3,analog4;
+    uint8_t data = 0,data2 = 0,i;
+    double analog[10],analog2[10],ave,ave2,sum,sum2;
+    wait(0.25);
+    for(i=0;i < 10;i++){
+        analog[i] = stick[0];
+        analog2[i] = stick[1];
+        sum += analog[i];
+        sum2 += analog2[i];
+        wait(0.10);
+    }
+    ave = sum/10;
+    ave2 = sum2/10;
+    testled[0] = 1;
+    wait(0.2);
+    
+    while(1) {
+        analog3 = stick[0];
+        analog4 = stick[1];
+        if(analog3 > ave-0.050 && analog3 < ave+0.050) {
+            signal = 0;
+            signal3 = 0;
+            data = 0;
+            mc.putc(data);
+            pc.printf("%f\n",data);
+            testled[0] = 0;
+            testled[1] = 0;
+        }else if(analog3 > ave-0.050){
+            signal = (analog3-ave)/ave;
+            data = (signal+0.005)*50;
+            mc.putc(data);
+            pc.printf("%f\n",data);
+            testled[0] = signal;
+            testled[1] = 0;
+        }else if(analog3 < ave+0.050){
+            signal3 = (analog3-ave)/ave*(-1);
+            data = (signal3+0.005)*50+64;
+            mc.putc(data);
+            pc.printf("%f\n",data);
+            testled[1] = signal3;
+            testled[0] = 0;
+        }
+        if(analog4 > ave2-0.050 && analog4 < ave2+0.050) {
+            signal2 = 0;
+            signal4 = 0;
+            data = 0;
+            mc.putc(data);
+            pc.printf("%f\n",data);
+            testled[2] = 0;
+            testled[3] = 0;
+        }else if(analog4 > ave2-0.050){
+            signal2 = (analog4-ave2)/ave2;
+            data = (signal2+0.005)*50+128;
+            mc.putc(data);
+            pc.printf("%f\n",data);
+            testled[2] = signal2;
+            testled[3] = 0;
+        }else if(analog4 < ave2+0.050){
+            signal4 = (analog4-ave2)/ave2*(-1);
+            data = (signal4+0.005)*50+192;
+            mc.putc(data);
+            pc.printf("%f\n",data);
+            testled[3] = signal4;
+            testled[2] = 0;
+        }
+        pc.printf("%u_%u_%f_%f_%f_%f",data,data2,signal,signal2,signal3,signal4);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Dec 21 06:34:09 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file