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.
DCmotor.cpp
00001 #include<DCmotor.hpp> 00002 00003 DCmotor::DCmotor(Port motor, float max_pwm, float min_pwm, bool CW_flag):motor_(motor),max_pwm_(max_pwm),min_pwm_(min_pwm),CW_flag_(CW_flag){ 00004 } 00005 00006 DCmotor::DCmotor(PinName pin_a, PinName pin_b, float max_pwm, float min_pwm, bool CW_flag):max_pwm_(max_pwm),min_pwm_(min_pwm),CW_flag_(CW_flag){ 00007 motor_.pin[0] = pin_a; 00008 motor_.pin[1] = pin_b; 00009 } 00010 00011 void DCmotor::drive(float pwm){ 00012 float output_pwm = (abs(pwm) < min_pwm_ ? min_pwm_ : abs(pwm) > max_pwm_ ? max_pwm_ : abs(pwm)); 00013 pwm = (CW_flag_ == false ? -pwm : pwm); 00014 if(!pwm) { 00015 DigitalOut Moter1(motor_.pin[0],0); 00016 DigitalOut Moter2(motor_.pin[1],0); 00017 } else if(pwm < 0) { 00018 PwmOut Moter1(motor_.pin[0]); 00019 Moter1.period_us(256); 00020 Moter1.write(output_pwm); 00021 DigitalOut Moter2(motor_.pin[1],0); 00022 } else { 00023 DigitalOut Moter1(motor_.pin[0],0); 00024 PwmOut Moter2(motor_.pin[1]); 00025 Moter2.period_us(256); 00026 Moter2.write(output_pwm); 00027 } 00028 }
Generated on Sat Oct 15 2022 07:52:33 by
1.7.2