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.
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[3] = "00";//実は末尾にnullがあるので、要素が4つでも配列では5つの箱を用意している 00013 char dam; 00014 00015 int rpm=0; 00016 00017 00018 void send(){ 00019 00020 char DATA[DATA_SIZE] = {':', '0', '1', '0', '1', '3', '9', 'X', '\r', '\n'}; 00021 //04 00022 /*:は送信時に必要なヘッダー。78は相手のID(0x78)。01は送信コマンドとして必要。 00023 39は任意の値。Xはチェックサムの省略形。 \r\nは改行コマンド*/ 00024 00025 for (int i = 0 ; i < DATA_SIZE ; i++){ 00026 twe.putc(DATA[i]); 00027 myled=1; 00028 00029 } 00030 00031 } 00032 00033 00034 int main() { 00035 pc.baud(115200); 00036 twe.baud(115200); 00037 00038 flipper.attach(&send, 0.05); 00039 00040 00041 while(1) { 00042 // pc.putc(twe.getc()); 00043 00044 00045 if(twe.getc()==':'){ 00046 if(twe.getc()=='0'){ 00047 if(twe.getc()=='1'){ 00048 dam=twe.getc(); 00049 dam=twe.getc(); 00050 00051 for (int i = 0; i <= 2; i++) { 00052 rpm_array[i] =twe.getc();//高度の受信rpm+1000の値を文字列として受け取る 00053 } 00054 00055 rpm = atoi(rpm_array); 00056 00057 pc.printf("%d\r\n",rpm); 00058 00059 }//if(twe.getc()=='0') 00060 }//if(twe.getc()==':') 00061 } 00062 00063 00064 }//while 00065 00066 00067 00068 }//main
Generated on Mon Jul 25 2022 19:00:47 by
1.7.2