![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
回転数計のデータをトワイライトから受け取って回転数を計算して表示します。
Dependencies: mbed
Fork of receive_twe by
Diff: main.cpp
- Revision:
- 6:71adef562691
- Parent:
- 5:ad7e6acda243
- Child:
- 7:0c3c1a484ebc
diff -r ad7e6acda243 -r 71adef562691 main.cpp --- a/main.cpp Sat Oct 22 22:27:29 2016 +0000 +++ b/main.cpp Wed Oct 26 10:13:10 2016 +0000 @@ -2,10 +2,11 @@ Serial pc(USBTX,USBRX); Serial twe(p13,p14); -char data[73]; +char data[74]; int data_count; int data_num; int z_int; +int offset = (int)'0'; float cadence; bool datas_title_flag=false; @@ -18,7 +19,7 @@ if(twe.readable()){ data[data_count]=twe.getc(); - if(data[data_count]=='\n'){ + if(data[data_count]=='\r'){ for(int i=0;i<73;i++) data[i]= NULL; data_num=0; pc.putc('!'); @@ -35,27 +36,26 @@ }else{ pc.putc(data[data_count]); } - } - if(data_num==6){ + }else if(data_num==6){ if(datas_title_flag){ pc.printf("\n\r voltage:"); datas_title_flag=false; }else{ pc.putc(data[data_count]); } - } - if(data_num==14){ + }else if(data_num==14){ if(datas_title_flag){ pc.printf("\n\r Z:"); datas_title_flag=false; }else{ pc.putc(data[data_count]); } - } - if(data_num==15){ - z_int = data[data_count-1] + data[data_count-2]*10 + data[data_count-3]*100; - if(data[data_count-4]!=0) z_int *= -1; - pc.printf("%d",z_int); + }else if(data_num==15){ + z_int = (int)data[data_count-1] + (int)data[data_count-2]*10 + (int)data[data_count-3]*100 - offset*111; + if(data[data_count-4]!='0') z_int *= -1; + pc.printf("\n%d",z_int); + //pc.putc('\n'); +// pc.putc(data[data_count]); } data_count++; }//else