first

Dependencies:   Motordriver mbed

main.cpp

Committer:
a1503yi
Date:
2016-08-04
Revision:
2:e8e1041179b9
Parent:
1:30d2ed68c9f6

File content as of revision 2:e8e1041179b9:

//#include "motordriver.h"
#include "mbed.h"
//#include <string>

// --- SpeedCntrPWM ---
PwmOut speed_in1(p22) ;  // IN1への出力
PwmOut speed_in2(p23) ;  // IN2への出力
Ticker min ; // 一定時間ごとに関数を呼ぶ割込み処理用オブジェクト
Serial pc(USBTX, USBRX); // tx, rx
Serial gps(p28,p27);

int cnt = 0;
int rpm = 0;
bool flag = false;


// 回転数の表示を更新する関数
void measure()
{
    rpm = cnt * 5 ; // rpm = cnt * ( 60秒 / 3秒 ) / 4回
    flag = true;
    cnt = 0;
}
int main() {
    
   wait(3);
   
   //myled1 = 1;
   //myled2 = 0;
   
   char buff[255];
   unsigned int c;

   float sp1, sp2;
    //lcd.cls();
    // Pwm の周期を100[mS]に設定
    speed_in1.period(0.1) ;
    speed_in2.period(0.1) ;   
    
    
    // 3秒ごとにmeasure関数を呼ぶ    
    min.attach(&measure ,3.0) ;  
    
    while(1) {
       
        sp1 = 1.0f;   // IN1のデューティ比 100%にする
        sp2 = 0.0f;
        speed_in1.write(sp1) ; // デューティ比の設定(モータにむかって右回転)
        speed_in2.write(sp2) ;
        wait(2);
        sp1 = 0.0f;
        sp2 = 1.0f;   // IN1のデューティ比 100%にする
        speed_in1.write(sp1) ; // デューティ比の設定(モータにむかって左回転)
        speed_in2.write(sp2) ;
        wait(2);
        sp1 = 0.0f;
        sp2 = 0.0f;
        speed_in1.write(sp1) ; // 停止
        speed_in2.write(sp2) ;
        
        //if ( flag == true ){  // 3秒ごとに表示を更新する
            //lcd.locate(0,1);
            //lcd.printf("rpm [%4d]",rpm) ;
        //    flag = false;
        //}   
        
    }
}