Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of twe-lite_main by
main.cpp
00001 #include "mbed.h" 00002 00003 #define DATA_SIZE 10 00004 00005 DigitalOut myled(LED1); 00006 00007 Serial pc(USBTX,USBRX); 00008 Serial twe(p9,p10); 00009 00010 Ticker flipper; 00011 00012 char rpm_array[5] = "0000";//実は末尾にnullがあるので、要素が4つでも配列では5つの箱を用意している 00013 char dam; 00014 00015 int rpm=0; 00016 00017 void send(){ 00018 00019 char DATA[DATA_SIZE] = {':', '0', '1', '0', '1', '3', '9', 'X', '\r', '\n'}; 00020 //04 00021 /*:は送信時に必要なヘッダー。78は相手のID(0x78)。01は送信コマンドとして必要。 00022 39は任意の値。Xはチェックサムの省略形。 \r\nは改行コマンド*/ 00023 00024 for (int i = 0 ; i < DATA_SIZE ; i++){ 00025 twe.putc(DATA[i]); 00026 myled=1; 00027 00028 } 00029 00030 00031 00032 } 00033 00034 00035 int main() { 00036 pc.baud(115200); 00037 twe.baud(115200); 00038 00039 flipper.attach(&send, 0.05); 00040 00041 00042 while(1) { 00043 // pc.putc(twe.getc()); 00044 00045 00046 if(twe.getc()==':'){ 00047 if(twe.getc()=='0'){ 00048 if(twe.getc()=='1'){ 00049 dam=twe.getc(); 00050 dam=twe.getc(); 00051 00052 00053 for (int i = 0; i < 4; i++) { 00054 rpm_array[i] =twe.getc();//高度の受信rpm+1000の値を文字列として受け取る 00055 } 00056 00057 rpm = atoi(rpm_array); 00058 00059 rpm-=1000; 00060 pc.printf("%d\r\n",rpm); 00061 00062 }//if(twe.getc()=='0') 00063 }//if(twe.getc()==':') 00064 } 00065 00066 00067 }//while 00068 00069 00070 00071 }//main
Generated on Wed Aug 3 2022 13:16:36 by
1.7.2
