![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
回転数計のデータをトワイライトから受け取って回転数を計算して表示します。
Dependencies: mbed
Fork of receive_twe by
main.cpp@4:36f4a7c41412, 2016-10-22 (annotated)
- Committer:
- tsumagari
- Date:
- Sat Oct 22 10:58:39 2016 +0000
- Revision:
- 4:36f4a7c41412
- Parent:
- 3:4189f06dec07
- Child:
- 5:ad7e6acda243
twe???????????????????z??????????????pc??????????
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:36f4a7c41412 | 5 | char data[73]; |
tsumagari | 4:36f4a7c41412 | 6 | int data_count; |
tsumagari | 4:36f4a7c41412 | 7 | int data_num; |
tsumagari | 4:36f4a7c41412 | 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 | 4:36f4a7c41412 | 13 | data_num=0; |
tsumagari | 4:36f4a7c41412 | 14 | data_count=0; |
tsumagari | 0:8876c8f2119f | 15 | while(1) { |
tsumagari | 0:8876c8f2119f | 16 | if(twe.readable()){ |
tsumagari | 4:36f4a7c41412 | 17 | data[data_count]=twe.getc(); |
tsumagari | 4:36f4a7c41412 | 18 | |
tsumagari | 4:36f4a7c41412 | 19 | if(data[data_count]=='\n'){ |
tsumagari | 4:36f4a7c41412 | 20 | for(int i=0;i<73;i++) data[i]= NULL; |
tsumagari | 4:36f4a7c41412 | 21 | data_num=0; |
tsumagari | 4:36f4a7c41412 | 22 | pc.putc('!'); |
tsumagari | 4:36f4a7c41412 | 23 | data_count=0; |
tsumagari | 4:36f4a7c41412 | 24 | }else{ |
tsumagari | 4:36f4a7c41412 | 25 | if(data[data_count]==';'){ |
tsumagari | 4:36f4a7c41412 | 26 | data_num++; |
tsumagari | 4:36f4a7c41412 | 27 | datas_title_flag=true; |
tsumagari | 4:36f4a7c41412 | 28 | } |
tsumagari | 4:36f4a7c41412 | 29 | if(data_num==1){ |
tsumagari | 4:36f4a7c41412 | 30 | if(datas_title_flag){ |
tsumagari | 4:36f4a7c41412 | 31 | pc.printf("\n\r time:"); |
tsumagari | 4:36f4a7c41412 | 32 | datas_title_flag=false; |
tsumagari | 4:36f4a7c41412 | 33 | }else{ |
tsumagari | 4:36f4a7c41412 | 34 | pc.putc(data[data_count]); |
tsumagari | 4:36f4a7c41412 | 35 | } |
tsumagari | 4:36f4a7c41412 | 36 | } |
tsumagari | 4:36f4a7c41412 | 37 | if(data_num==6){ |
tsumagari | 4:36f4a7c41412 | 38 | if(datas_title_flag){ |
tsumagari | 4:36f4a7c41412 | 39 | pc.printf("\n\r voltage:"); |
tsumagari | 4:36f4a7c41412 | 40 | datas_title_flag=false; |
tsumagari | 4:36f4a7c41412 | 41 | }else{ |
tsumagari | 4:36f4a7c41412 | 42 | pc.putc(data[data_count]); |
tsumagari | 4:36f4a7c41412 | 43 | } |
tsumagari | 4:36f4a7c41412 | 44 | } |
tsumagari | 4:36f4a7c41412 | 45 | if(data_num==14){ |
tsumagari | 4:36f4a7c41412 | 46 | if(datas_title_flag){ |
tsumagari | 4:36f4a7c41412 | 47 | pc.printf("\n\r Z:"); |
tsumagari | 4:36f4a7c41412 | 48 | datas_title_flag=false; |
tsumagari | 4:36f4a7c41412 | 49 | }else{ |
tsumagari | 4:36f4a7c41412 | 50 | pc.putc(data[data_count]); |
tsumagari | 4:36f4a7c41412 | 51 | } |
tsumagari | 4:36f4a7c41412 | 52 | } |
tsumagari | 4:36f4a7c41412 | 53 | data_count++; |
tsumagari | 4:36f4a7c41412 | 54 | }//else |
tsumagari | 4:36f4a7c41412 | 55 | |
tsumagari | 4:36f4a7c41412 | 56 | } //readable |
tsumagari | 4:36f4a7c41412 | 57 | }//while |
tsumagari | 4:36f4a7c41412 | 58 | } //main |
tsumagari | 4:36f4a7c41412 | 59 | //一行72文字 |