2つのanalogスティックのanalog値をserial通信で送信、LEDをpwm制御するプログラムの受信側。2本入力時は正常,1本のみ入力時不具合(LED点滅)あり。直したら使えるようになります。
Dependencies: mbed
※解決策思いつかず。放置済み。※
Revision 0:4bcbb11cf9b1, committed 2014-12-21
- Comitter:
- eil4nyqn
- Date:
- Sun Dec 21 06:24:17 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:24:17 2014 +0000 @@ -0,0 +1,106 @@ +#include "mbed.h" + +Serial pc(USBTX,USBRX); +Serial mc(p13,p14); +//PwmOut myled[] = {p21,p22,p23,p24}; +PwmOut myled[] = {LED1,LED2,LED3,LED4}; +BusOut select(p5,p6,p7,p8); +Timer test; +Timer test2; + +int main() { + double signal,signal2; + uint8_t i = 0,data,data2; + int style = 0,style2 = 0; + double time = 0,time2 = 0; + + while(1) { + if(mc.readable() == 1){ + data = mc.getc(); + test.reset(); + test.start(); + + if(data < 64 && data > 2){ + signal = data/50.00; + i = 0; + myled[i] = signal; + style = 1; + select = style; + }else if(data > 64 && data < 128){ + signal = (data-64)/50.00; + i = 1; + myled[i] = signal; + style = 2; + select = style; + }else if(data < 196 && data > 128){ + signal = (data-126)/50.00; + i = 2; + myled[i] = signal; + style = 4; + select = style; + }else if(data > 196 && data < 256){ + signal = (data-196)/50.00; + i = 3; + myled[i] = signal; + style = 8; + select = style; + }else{ + myled[0] = 0; + myled[1] = 0; + myled[2] = 0; + myled[3] = 0; + } + test.stop(); + time = test.read(); + pc.printf("%u_%f_%f_%u\n",data,signal,time,style); + + if(mc.readable() == 1){ + data2 = mc.getc(); + test2.start(); + if(data2 < 64 && data2 > 2){ + signal2 = data2/50.00; + myled[0] = signal2; + + if(i > 1){ + + }else if(data2 > 64 && data2 < 128){ + signal2 = (data2-64)/50.00; + myled[1] = signal2; + style2 = 2; + style2 +=style; + myled[i] = signal; + mosw = style2; + }else if(data2 < 196 && data2 > 128){ + signal2 = (data2-126)/50.00; + myled[3] = signal2; + style2 = 4; + style2 += style; + myled[i] = signal; + mosw = style2; + //test2.start(); + }else if(data2 < 256 && data2 > 196){ + signal2 = (data2-196)/50.00; + myled[3] = signal2; + style2 = 4; + style2 += style; + myled[i] = signal; + mosw = style; + //test2.start(); + }else{ + myled[0] = 0; + myled[1] = 0; + myled[2] = 0; + myled[3] = 0; + } + test2.stop(); + time2 = test2.read(); + pc.printf("%u_%f_%f_%u\n",data2,signal2,time2,style2); + i = 0; + }else{ + myled[0] = 0; + myled[1] = 0; + myled[2] = 0; + myled[3] = 0; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Dec 21 06:24:17 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file