![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
回転数計のデータをトワイライトから受け取って回転数を計算して表示します。
Dependencies: mbed
Fork of receive_twe by
main.cpp
- Committer:
- tsumagari
- Date:
- 2016-10-22
- Revision:
- 5:ad7e6acda243
- Parent:
- 4:36f4a7c41412
- Child:
- 6:71adef562691
File content as of revision 5:ad7e6acda243:
#include "mbed.h" Serial pc(USBTX,USBRX); Serial twe(p13,p14); char data[73]; int data_count; int data_num; int z_int; float cadence; bool datas_title_flag=false; int main() { twe.baud(115200); pc.baud(115200); data_num=0; data_count=0; while(1) { if(twe.readable()){ data[data_count]=twe.getc(); if(data[data_count]=='\n'){ for(int i=0;i<73;i++) data[i]= NULL; data_num=0; pc.putc('!'); data_count=0; }else{ if(data[data_count]==';'){ data_num++; datas_title_flag=true; } if(data_num==1){ if(datas_title_flag){ pc.printf("\n\r time:"); datas_title_flag=false; }else{ pc.putc(data[data_count]); } } 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){ 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); } data_count++; }//else } //readable }//while } //main //一行72文字