first
Dependencies: Motordriver mbed
main.cpp
- Committer:
- a1503yi
- Date:
- 2016-08-04
- Revision:
- 0:86c24595c963
- Child:
- 1:30d2ed68c9f6
File content as of revision 0:86c24595c963:
#include "motordriver.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; //lcd.locate(0,0); //lcd.printf("High Speed"); 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); //if ( flag == true ){ // 3秒ごとに表示を更新する //lcd.locate(0,1); //lcd.printf("rpm [%4d]",rpm) ; // flag = false; //} } }