2つのanalogスティックのanalog値をserial通信で送信、LEDをpwm制御するプログラムの受信側。2本入力時は正常,1本のみ入力時不具合(LED点滅)あり。直したら使えるようになります。
Dependencies: mbed
※解決策思いつかず。放置済み。※
main.cpp@0:420300781c80, 2014-12-21 (annotated)
- Committer:
- eil4nyqn
- Date:
- Sun Dec 21 07:04:04 2014 +0000
- Revision:
- 0:420300781c80
www
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eil4nyqn | 0:420300781c80 | 1 | #include "mbed.h" |
eil4nyqn | 0:420300781c80 | 2 | |
eil4nyqn | 0:420300781c80 | 3 | Serial pc(USBTX,USBRX); |
eil4nyqn | 0:420300781c80 | 4 | Serial mc(p13,p14); |
eil4nyqn | 0:420300781c80 | 5 | BusOut select(p5,p6,p7,p8); |
eil4nyqn | 0:420300781c80 | 6 | PwmOut myled[] = {LED1,LED2,LED3,LED4}; |
eil4nyqn | 0:420300781c80 | 7 | Timer first; |
eil4nyqn | 0:420300781c80 | 8 | Timer second; |
eil4nyqn | 0:420300781c80 | 9 | Timeout next; |
eil4nyqn | 0:420300781c80 | 10 | |
eil4nyqn | 0:420300781c80 | 11 | void test(){ |
eil4nyqn | 0:420300781c80 | 12 | double signal2,time2; |
eil4nyqn | 0:420300781c80 | 13 | uint8_t data2; |
eil4nyqn | 0:420300781c80 | 14 | int style2 = 0; |
eil4nyqn | 0:420300781c80 | 15 | |
eil4nyqn | 0:420300781c80 | 16 | if(mc.readable() == 1){ |
eil4nyqn | 0:420300781c80 | 17 | data2 = mc.getc(); |
eil4nyqn | 0:420300781c80 | 18 | second.reset(); |
eil4nyqn | 0:420300781c80 | 19 | second.start(); |
eil4nyqn | 0:420300781c80 | 20 | if(data2 > 0 && data2 < 64) { |
eil4nyqn | 0:420300781c80 | 21 | signal2 = data2/50.00; |
eil4nyqn | 0:420300781c80 | 22 | style2 = 1; |
eil4nyqn | 0:420300781c80 | 23 | myled[0] = signal2; |
eil4nyqn | 0:420300781c80 | 24 | myled[1] = 0; |
eil4nyqn | 0:420300781c80 | 25 | select = style2; |
eil4nyqn | 0:420300781c80 | 26 | }else if(data2 > 64 && data2 < 128) { |
eil4nyqn | 0:420300781c80 | 27 | signal2 = (data2-64)/50.00; |
eil4nyqn | 0:420300781c80 | 28 | style2 = 2; |
eil4nyqn | 0:420300781c80 | 29 | myled[1] = signal2; |
eil4nyqn | 0:420300781c80 | 30 | myled[0] = 0; |
eil4nyqn | 0:420300781c80 | 31 | select = style2; |
eil4nyqn | 0:420300781c80 | 32 | }else if(data2 > 128 && data2 < 196) { |
eil4nyqn | 0:420300781c80 | 33 | signal2 = (data2-128)/50.00; |
eil4nyqn | 0:420300781c80 | 34 | style2 = 4; |
eil4nyqn | 0:420300781c80 | 35 | myled[2] = signal2; |
eil4nyqn | 0:420300781c80 | 36 | myled[3] = 0; |
eil4nyqn | 0:420300781c80 | 37 | select = style2; |
eil4nyqn | 0:420300781c80 | 38 | }else if(data2 > 196 && data2 < 256) { |
eil4nyqn | 0:420300781c80 | 39 | signal2 = (data2-196)/50.00; |
eil4nyqn | 0:420300781c80 | 40 | style2 = 8; |
eil4nyqn | 0:420300781c80 | 41 | myled[3] = signal2; |
eil4nyqn | 0:420300781c80 | 42 | myled[2] = 0; |
eil4nyqn | 0:420300781c80 | 43 | select = style2; |
eil4nyqn | 0:420300781c80 | 44 | }else{ |
eil4nyqn | 0:420300781c80 | 45 | myled[0] = 0; |
eil4nyqn | 0:420300781c80 | 46 | myled[1] = 0; |
eil4nyqn | 0:420300781c80 | 47 | myled[2] = 0; |
eil4nyqn | 0:420300781c80 | 48 | myled[3] = 0; |
eil4nyqn | 0:420300781c80 | 49 | } |
eil4nyqn | 0:420300781c80 | 50 | second.stop(); |
eil4nyqn | 0:420300781c80 | 51 | time2 = second.read_us(); |
eil4nyqn | 0:420300781c80 | 52 | pc.printf("%u_%f__%u_%f\n",data2,signal2,style2,time2); |
eil4nyqn | 0:420300781c80 | 53 | } |
eil4nyqn | 0:420300781c80 | 54 | } |
eil4nyqn | 0:420300781c80 | 55 | int main() { |
eil4nyqn | 0:420300781c80 | 56 | double signal,time; |
eil4nyqn | 0:420300781c80 | 57 | uint8_t data; |
eil4nyqn | 0:420300781c80 | 58 | int style = 0; |
eil4nyqn | 0:420300781c80 | 59 | |
eil4nyqn | 0:420300781c80 | 60 | while(1) { |
eil4nyqn | 0:420300781c80 | 61 | if(mc.readable() == 1) { |
eil4nyqn | 0:420300781c80 | 62 | data = mc.getc(); |
eil4nyqn | 0:420300781c80 | 63 | first.reset(); |
eil4nyqn | 0:420300781c80 | 64 | first.start(); |
eil4nyqn | 0:420300781c80 | 65 | if(data > 0 && data<64) { |
eil4nyqn | 0:420300781c80 | 66 | signal = data/50.00; |
eil4nyqn | 0:420300781c80 | 67 | style = 1; |
eil4nyqn | 0:420300781c80 | 68 | myled[0] = signal; |
eil4nyqn | 0:420300781c80 | 69 | myled[1] = 0; |
eil4nyqn | 0:420300781c80 | 70 | select = style; |
eil4nyqn | 0:420300781c80 | 71 | }else if(data > 64 && data < 128) { |
eil4nyqn | 0:420300781c80 | 72 | signal = (data-64)/50.00; |
eil4nyqn | 0:420300781c80 | 73 | style = 2; |
eil4nyqn | 0:420300781c80 | 74 | myled[1] = signal; |
eil4nyqn | 0:420300781c80 | 75 | myled[0] = 0; |
eil4nyqn | 0:420300781c80 | 76 | select = style; |
eil4nyqn | 0:420300781c80 | 77 | }else if(data > 128 && data < 196) { |
eil4nyqn | 0:420300781c80 | 78 | signal = (data-128)/50.00; |
eil4nyqn | 0:420300781c80 | 79 | style = 4; |
eil4nyqn | 0:420300781c80 | 80 | myled[2] = signal; |
eil4nyqn | 0:420300781c80 | 81 | myled[3] = 0; |
eil4nyqn | 0:420300781c80 | 82 | select = style; |
eil4nyqn | 0:420300781c80 | 83 | }else if(data >196 && data < 256) { |
eil4nyqn | 0:420300781c80 | 84 | signal = (data-196)/50.00; |
eil4nyqn | 0:420300781c80 | 85 | style = 8; |
eil4nyqn | 0:420300781c80 | 86 | myled[3] = signal; |
eil4nyqn | 0:420300781c80 | 87 | myled[2] = 0; |
eil4nyqn | 0:420300781c80 | 88 | select = style; |
eil4nyqn | 0:420300781c80 | 89 | }else{ |
eil4nyqn | 0:420300781c80 | 90 | myled[0] = 0; |
eil4nyqn | 0:420300781c80 | 91 | myled[1] = 0; |
eil4nyqn | 0:420300781c80 | 92 | myled[2] = 0; |
eil4nyqn | 0:420300781c80 | 93 | myled[3] = 0; |
eil4nyqn | 0:420300781c80 | 94 | } |
eil4nyqn | 0:420300781c80 | 95 | first.stop(); |
eil4nyqn | 0:420300781c80 | 96 | time = first.read_us(); |
eil4nyqn | 0:420300781c80 | 97 | pc.printf("%u_%f_%u_%f\n",data,signal,style,time); |
eil4nyqn | 0:420300781c80 | 98 | next.attach_us(test,time); |
eil4nyqn | 0:420300781c80 | 99 | } |
eil4nyqn | 0:420300781c80 | 100 | } |
eil4nyqn | 0:420300781c80 | 101 | } |