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

Dependencies:   mbed

Fork of twe_lite_rpm by Atsumi Toda

main.cpp

Committer:
Joeatsumi
Date:
2018-02-25
Revision:
1:7c604d96b162
Parent:
0:25af5436ac17

File content as of revision 1:7c604d96b162:

#include "mbed.h"
//Serial twe(p9, p10); // tx, rx
Serial pc(USBTX,USBRX);
DigitalOut myled(LED1);

#define DATA_SIZE 11

char s[11] ;//this can take up to 10 byte characters

char dam;
short int rpm=76;
struct{
    char highbyte;
    char lowbyte;
    short intdat;
    }data;

char highbyte,lowbyte;


void rec(){
                     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);
       
    while(1) {
                             //pc.putc(twe.getc());
             if(pc.getc()==':'){
                 if(pc.getc()=='0'){
                     if(pc.getc()=='4'){
                        dam=pc.getc();
                        dam=pc.getc();
                        if(pc.getc()=='3'){
                        if(pc.getc()=='9'){
                               
                               rec();
                               
                               }
                                      }//if(twe.getc()=='9')
                                }//if(twe.getc()=='4')
                               }//0
                
        
                    }//:
             }//while

}