2つのanalogスティックのanalog値をserial通信で送信、LEDをpwm制御するプログラムの受信側。2本入力時は正常,1本のみ入力時不具合(LED点滅)あり。直したら使えるようになります。

Dependencies:   mbed

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

Committer:
eil4nyqn
Date:
Sun Dec 21 06:24:17 2014 +0000
Revision:
0:4bcbb11cf9b1
www;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eil4nyqn 0:4bcbb11cf9b1 1 #include "mbed.h"
eil4nyqn 0:4bcbb11cf9b1 2
eil4nyqn 0:4bcbb11cf9b1 3 Serial pc(USBTX,USBRX);
eil4nyqn 0:4bcbb11cf9b1 4 Serial mc(p13,p14);
eil4nyqn 0:4bcbb11cf9b1 5 //PwmOut myled[] = {p21,p22,p23,p24};
eil4nyqn 0:4bcbb11cf9b1 6 PwmOut myled[] = {LED1,LED2,LED3,LED4};
eil4nyqn 0:4bcbb11cf9b1 7 BusOut select(p5,p6,p7,p8);
eil4nyqn 0:4bcbb11cf9b1 8 Timer test;
eil4nyqn 0:4bcbb11cf9b1 9 Timer test2;
eil4nyqn 0:4bcbb11cf9b1 10
eil4nyqn 0:4bcbb11cf9b1 11 int main() {
eil4nyqn 0:4bcbb11cf9b1 12 double signal,signal2;
eil4nyqn 0:4bcbb11cf9b1 13 uint8_t i = 0,data,data2;
eil4nyqn 0:4bcbb11cf9b1 14 int style = 0,style2 = 0;
eil4nyqn 0:4bcbb11cf9b1 15 double time = 0,time2 = 0;
eil4nyqn 0:4bcbb11cf9b1 16
eil4nyqn 0:4bcbb11cf9b1 17 while(1) {
eil4nyqn 0:4bcbb11cf9b1 18 if(mc.readable() == 1){
eil4nyqn 0:4bcbb11cf9b1 19 data = mc.getc();
eil4nyqn 0:4bcbb11cf9b1 20 test.reset();
eil4nyqn 0:4bcbb11cf9b1 21 test.start();
eil4nyqn 0:4bcbb11cf9b1 22
eil4nyqn 0:4bcbb11cf9b1 23 if(data < 64 && data > 2){
eil4nyqn 0:4bcbb11cf9b1 24 signal = data/50.00;
eil4nyqn 0:4bcbb11cf9b1 25 i = 0;
eil4nyqn 0:4bcbb11cf9b1 26 myled[i] = signal;
eil4nyqn 0:4bcbb11cf9b1 27 style = 1;
eil4nyqn 0:4bcbb11cf9b1 28 select = style;
eil4nyqn 0:4bcbb11cf9b1 29 }else if(data > 64 && data < 128){
eil4nyqn 0:4bcbb11cf9b1 30 signal = (data-64)/50.00;
eil4nyqn 0:4bcbb11cf9b1 31 i = 1;
eil4nyqn 0:4bcbb11cf9b1 32 myled[i] = signal;
eil4nyqn 0:4bcbb11cf9b1 33 style = 2;
eil4nyqn 0:4bcbb11cf9b1 34 select = style;
eil4nyqn 0:4bcbb11cf9b1 35 }else if(data < 196 && data > 128){
eil4nyqn 0:4bcbb11cf9b1 36 signal = (data-126)/50.00;
eil4nyqn 0:4bcbb11cf9b1 37 i = 2;
eil4nyqn 0:4bcbb11cf9b1 38 myled[i] = signal;
eil4nyqn 0:4bcbb11cf9b1 39 style = 4;
eil4nyqn 0:4bcbb11cf9b1 40 select = style;
eil4nyqn 0:4bcbb11cf9b1 41 }else if(data > 196 && data < 256){
eil4nyqn 0:4bcbb11cf9b1 42 signal = (data-196)/50.00;
eil4nyqn 0:4bcbb11cf9b1 43 i = 3;
eil4nyqn 0:4bcbb11cf9b1 44 myled[i] = signal;
eil4nyqn 0:4bcbb11cf9b1 45 style = 8;
eil4nyqn 0:4bcbb11cf9b1 46 select = style;
eil4nyqn 0:4bcbb11cf9b1 47 }else{
eil4nyqn 0:4bcbb11cf9b1 48 myled[0] = 0;
eil4nyqn 0:4bcbb11cf9b1 49 myled[1] = 0;
eil4nyqn 0:4bcbb11cf9b1 50 myled[2] = 0;
eil4nyqn 0:4bcbb11cf9b1 51 myled[3] = 0;
eil4nyqn 0:4bcbb11cf9b1 52 }
eil4nyqn 0:4bcbb11cf9b1 53 test.stop();
eil4nyqn 0:4bcbb11cf9b1 54 time = test.read();
eil4nyqn 0:4bcbb11cf9b1 55 pc.printf("%u_%f_%f_%u\n",data,signal,time,style);
eil4nyqn 0:4bcbb11cf9b1 56
eil4nyqn 0:4bcbb11cf9b1 57 if(mc.readable() == 1){
eil4nyqn 0:4bcbb11cf9b1 58 data2 = mc.getc();
eil4nyqn 0:4bcbb11cf9b1 59 test2.start();
eil4nyqn 0:4bcbb11cf9b1 60 if(data2 < 64 && data2 > 2){
eil4nyqn 0:4bcbb11cf9b1 61 signal2 = data2/50.00;
eil4nyqn 0:4bcbb11cf9b1 62 myled[0] = signal2;
eil4nyqn 0:4bcbb11cf9b1 63
eil4nyqn 0:4bcbb11cf9b1 64 if(i > 1){
eil4nyqn 0:4bcbb11cf9b1 65
eil4nyqn 0:4bcbb11cf9b1 66 }else if(data2 > 64 && data2 < 128){
eil4nyqn 0:4bcbb11cf9b1 67 signal2 = (data2-64)/50.00;
eil4nyqn 0:4bcbb11cf9b1 68 myled[1] = signal2;
eil4nyqn 0:4bcbb11cf9b1 69 style2 = 2;
eil4nyqn 0:4bcbb11cf9b1 70 style2 +=style;
eil4nyqn 0:4bcbb11cf9b1 71 myled[i] = signal;
eil4nyqn 0:4bcbb11cf9b1 72 mosw = style2;
eil4nyqn 0:4bcbb11cf9b1 73 }else if(data2 < 196 && data2 > 128){
eil4nyqn 0:4bcbb11cf9b1 74 signal2 = (data2-126)/50.00;
eil4nyqn 0:4bcbb11cf9b1 75 myled[3] = signal2;
eil4nyqn 0:4bcbb11cf9b1 76 style2 = 4;
eil4nyqn 0:4bcbb11cf9b1 77 style2 += style;
eil4nyqn 0:4bcbb11cf9b1 78 myled[i] = signal;
eil4nyqn 0:4bcbb11cf9b1 79 mosw = style2;
eil4nyqn 0:4bcbb11cf9b1 80 //test2.start();
eil4nyqn 0:4bcbb11cf9b1 81 }else if(data2 < 256 && data2 > 196){
eil4nyqn 0:4bcbb11cf9b1 82 signal2 = (data2-196)/50.00;
eil4nyqn 0:4bcbb11cf9b1 83 myled[3] = signal2;
eil4nyqn 0:4bcbb11cf9b1 84 style2 = 4;
eil4nyqn 0:4bcbb11cf9b1 85 style2 += style;
eil4nyqn 0:4bcbb11cf9b1 86 myled[i] = signal;
eil4nyqn 0:4bcbb11cf9b1 87 mosw = style;
eil4nyqn 0:4bcbb11cf9b1 88 //test2.start();
eil4nyqn 0:4bcbb11cf9b1 89 }else{
eil4nyqn 0:4bcbb11cf9b1 90 myled[0] = 0;
eil4nyqn 0:4bcbb11cf9b1 91 myled[1] = 0;
eil4nyqn 0:4bcbb11cf9b1 92 myled[2] = 0;
eil4nyqn 0:4bcbb11cf9b1 93 myled[3] = 0;
eil4nyqn 0:4bcbb11cf9b1 94 }
eil4nyqn 0:4bcbb11cf9b1 95 test2.stop();
eil4nyqn 0:4bcbb11cf9b1 96 time2 = test2.read();
eil4nyqn 0:4bcbb11cf9b1 97 pc.printf("%u_%f_%f_%u\n",data2,signal2,time2,style2);
eil4nyqn 0:4bcbb11cf9b1 98 i = 0;
eil4nyqn 0:4bcbb11cf9b1 99 }else{
eil4nyqn 0:4bcbb11cf9b1 100 myled[0] = 0;
eil4nyqn 0:4bcbb11cf9b1 101 myled[1] = 0;
eil4nyqn 0:4bcbb11cf9b1 102 myled[2] = 0;
eil4nyqn 0:4bcbb11cf9b1 103 myled[3] = 0;
eil4nyqn 0:4bcbb11cf9b1 104 }
eil4nyqn 0:4bcbb11cf9b1 105 }
eil4nyqn 0:4bcbb11cf9b1 106 }