twe-liteを用いた実験用プログラム。回転数をメイン側へ送信する目的で書いた。

Dependencies:   mbed

Fork of twe_lite_rpm by Atsumi Toda

Revision:
1:7c604d96b162
Parent:
0:25af5436ac17
--- a/main.cpp	Fri Feb 23 04:21:22 2018 +0000
+++ b/main.cpp	Sun Feb 25 05:31:09 2018 +0000
@@ -3,28 +3,30 @@
 Serial pc(USBTX,USBRX);
 DigitalOut myled(LED1);
 
-#define DATA_SIZE 10
+#define DATA_SIZE 11
+
+char s[11] ;//this can take up to 10 byte characters
 
 char dam;
-int rpm=76;
+short int rpm=76;
 struct{
     char highbyte;
     char lowbyte;
     short intdat;
     }data;
 
+char highbyte,lowbyte;
+
+
 void rec(){
-     char DATA[DATA_SIZE] = {':', '0', '4', '0', '1', '3', '9', 'X', '\r', '\n'};
-                //04
-                /*:は送信時に必要なヘッダー。78は相手のID(0x78)。01は送信コマンドとして必要。
-                  39は任意の値。Xはチェックサムの省略形。 \r\nは改行コマンド*/
-                  
-                for (int  i = 0 ; i < DATA_SIZE ; i++){  
-                     pc.putc(DATA[i]);
-                     myled=1;
+                     rpm+=1000;
                      
-                     }
-                     
+                sprintf(s, ":0401%dX\r\n",rpm);
+                /*配列sにまとめて代入。*/
+                 for (int  i = 0 ; i < DATA_SIZE ; i++){  
+                      pc.putc(s[i]);
+                     }  
+                     rpm-=1000;
     }
 int main() {
        pc.baud(115200);