twe-liteを使った受信プログラム。透過モードに非ず。

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Serial twe(p9, p10); // tx, rx
00003 Serial pc(USBTX,USBRX);
00004 
00005 char rpm_array[5] = "0000";//実は末尾にnullがあるので、要素が4つでも配列では5つの箱を用意している
00006 char dam;
00007 
00008 int rpm=0;
00009 
00010 DigitalOut myled(LED1);
00011 
00012 void rpm_f()//文字列から数値への変換
00013 {
00014     
00015     rpm = atoi(rpm_array);
00016     rpm-=1000;
00017     
00018 }
00019 
00020 
00021 int main() {
00022     
00023     twe.baud(115200);
00024     pc.baud(115200);
00025     
00026     while(1) {
00027         
00028         if(twe.getc()==':'){
00029             if(twe.getc()=='0'){//送信してきた相手のIDは0x01
00030                 if(twe.getc()=='1'){
00031                     dam=twe.getc();//数値とは関係ないのでdamに入れて無視をする
00032                     dam=twe.getc();//
00033                             for (int i = 0; i <= 4; i++) {
00034                                rpm_array[i] =twe.getc();//高度の受信rpm+1000の値を文字列として受け取る
00035                                
00036                                }
00037                     }
00038                 }
00039             }
00040             
00041             rpm_f();
00042         pc.printf("Rpm=%d",rpm);
00043         
00044     }//while
00045 }//int main()