回転数計のデータをトワイライトから受け取って回転数を計算して表示します。

Dependencies:   mbed

Fork of receive_twe by natsu tsumagari

Committer:
tsumagari
Date:
Sat Oct 22 09:11:28 2016 +0000
Revision:
2:f82d4b3f338f
Parent:
1:c1f5bd2b296c
Child:
3:4189f06dec07
??????????????????????????????????; twe???????????????????????????????????????????pc?????...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsumagari 0:8876c8f2119f 1 #include "mbed.h"
tsumagari 0:8876c8f2119f 2
tsumagari 0:8876c8f2119f 3 Serial pc(USBTX,USBRX);
tsumagari 0:8876c8f2119f 4 Serial twe(p13,p14);
tsumagari 2:f82d4b3f338f 5 char data[74];
tsumagari 2:f82d4b3f338f 6 int data_count;
tsumagari 1:c1f5bd2b296c 7 int data_num;
tsumagari 2:f82d4b3f338f 8 bool datas_title_flag=false;
tsumagari 0:8876c8f2119f 9
tsumagari 0:8876c8f2119f 10 int main() {
tsumagari 0:8876c8f2119f 11 twe.baud(115200);
tsumagari 0:8876c8f2119f 12 pc.baud(115200);
tsumagari 1:c1f5bd2b296c 13 data_num=0;
tsumagari 2:f82d4b3f338f 14 data_count=0;
tsumagari 0:8876c8f2119f 15 while(1) {
tsumagari 0:8876c8f2119f 16 if(twe.readable()){
tsumagari 2:f82d4b3f338f 17 data[data_count]=twe.getc();
tsumagari 1:c1f5bd2b296c 18
tsumagari 2:f82d4b3f338f 19 if(data[data_count]==';'){
tsumagari 2:f82d4b3f338f 20 pc.putc((char)data_num);
tsumagari 2:f82d4b3f338f 21 data_num++;
tsumagari 2:f82d4b3f338f 22 datas_title_flag=true;
tsumagari 2:f82d4b3f338f 23 }
tsumagari 2:f82d4b3f338f 24 if(data_num==1){
tsumagari 2:f82d4b3f338f 25 if(datas_title_flag){
tsumagari 2:f82d4b3f338f 26 pc.printf("\n\r time:");
tsumagari 2:f82d4b3f338f 27 datas_title_flag=false;
tsumagari 2:f82d4b3f338f 28 }else{
tsumagari 2:f82d4b3f338f 29 pc.putc(data[data_count]);
tsumagari 2:f82d4b3f338f 30 }
tsumagari 2:f82d4b3f338f 31 data_count++;
tsumagari 2:f82d4b3f338f 32 }
tsumagari 2:f82d4b3f338f 33 if(data_num==2){
tsumagari 2:f82d4b3f338f 34 if(datas_title_flag){
tsumagari 2:f82d4b3f338f 35 datas_title_flag=false;
tsumagari 2:f82d4b3f338f 36 data_count++;
tsumagari 2:f82d4b3f338f 37 }else if(data[data_count]=='\n\r'){
tsumagari 2:f82d4b3f338f 38 for(int i=0;i<74;i++) data[i]= NULL;
tsumagari 2:f82d4b3f338f 39 data_num=0;
tsumagari 2:f82d4b3f338f 40 pc.putc('!');
tsumagari 2:f82d4b3f338f 41 data_count=0;
tsumagari 2:f82d4b3f338f 42 }else data_count++;
tsumagari 2:f82d4b3f338f 43 }
tsumagari 2:f82d4b3f338f 44 if(data_num==6){
tsumagari 2:f82d4b3f338f 45 if(datas_title_flag){
tsumagari 2:f82d4b3f338f 46 pc.printf("\n\r voltage:");
tsumagari 2:f82d4b3f338f 47 datas_title_flag=false;
tsumagari 2:f82d4b3f338f 48 }else{
tsumagari 2:f82d4b3f338f 49 pc.putc(data[data_count]);
tsumagari 2:f82d4b3f338f 50 }
tsumagari 2:f82d4b3f338f 51 data_count++;
tsumagari 2:f82d4b3f338f 52 }
tsumagari 2:f82d4b3f338f 53 //if(data_num==12){
tsumagari 2:f82d4b3f338f 54 // if(!datas_title_flag){
tsumagari 2:f82d4b3f338f 55 // pc.printf("\n\r X:");
tsumagari 2:f82d4b3f338f 56 // datas_title_flag=true;
tsumagari 2:f82d4b3f338f 57 // }else{
tsumagari 2:f82d4b3f338f 58 // pc.putc(data[data_count])
tsumagari 2:f82d4b3f338f 59 // }
tsumagari 2:f82d4b3f338f 60 // }
tsumagari 2:f82d4b3f338f 61 // if(data_num==13){
tsumagari 2:f82d4b3f338f 62 // if(!datas_title_flag){
tsumagari 2:f82d4b3f338f 63 // pc.printf("\n\r Y:");
tsumagari 2:f82d4b3f338f 64 // datas_title_flag=true;
tsumagari 2:f82d4b3f338f 65 // }else{
tsumagari 2:f82d4b3f338f 66 // pc.putc(data[data_count]);
tsumagari 2:f82d4b3f338f 67 // }
tsumagari 2:f82d4b3f338f 68 // }
tsumagari 2:f82d4b3f338f 69 if(data_num==14){
tsumagari 2:f82d4b3f338f 70 if(datas_title_flag){
tsumagari 2:f82d4b3f338f 71 pc.printf("\n\r Z:");
tsumagari 2:f82d4b3f338f 72 datas_title_flag=false;
tsumagari 2:f82d4b3f338f 73 }else{
tsumagari 2:f82d4b3f338f 74 pc.putc(data[data_count]);
tsumagari 2:f82d4b3f338f 75 }
tsumagari 2:f82d4b3f338f 76 data_count++;
tsumagari 2:f82d4b3f338f 77 }
tsumagari 2:f82d4b3f338f 78 if(data_num==15){
tsumagari 2:f82d4b3f338f 79 if(datas_title_flag){
tsumagari 2:f82d4b3f338f 80 datas_title_flag=false;
tsumagari 2:f82d4b3f338f 81 data_count++;
tsumagari 2:f82d4b3f338f 82 }else{
tsumagari 2:f82d4b3f338f 83 for(int i=0;i<74;i++)data[i]=NULL;
tsumagari 2:f82d4b3f338f 84 data_num=0;
tsumagari 2:f82d4b3f338f 85 data_count=0;
tsumagari 2:f82d4b3f338f 86 }
tsumagari 2:f82d4b3f338f 87
tsumagari 2:f82d4b3f338f 88 }
tsumagari 2:f82d4b3f338f 89
tsumagari 2:f82d4b3f338f 90
tsumagari 2:f82d4b3f338f 91
tsumagari 2:f82d4b3f338f 92 } //readable
tsumagari 2:f82d4b3f338f 93 }//while
tsumagari 2:f82d4b3f338f 94 } //main
tsumagari 2:f82d4b3f338f 95 //一行72文字