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.
Motor.cpp
00001 #include "Motor.h" 00002 00003 00004 Motor::Motor(PinName IN1, PinName IN2, PinName INH1, PinName INH2) 00005 : IN1_(IN1), IN2_(IN2), INH1_(INH1), INH2_(INH2) 00006 { 00007 INH1_=1; 00008 INH2_=1; 00009 IN1_.period_us(50); 00010 IN2_.period_us(50); 00011 } 00012 00013 void Motor::setSpeed_percent(float percent, char direction) 00014 { 00015 float duty = percent/100.0; 00016 if(duty>1.0) { 00017 duty=1.0; 00018 } else if(duty<0.0) { 00019 duty=0.0; 00020 } 00021 00022 if(direction==FORWARD) 00023 { 00024 IN1_=0; 00025 IN2_=duty; 00026 } 00027 else if (direction == BACKWARD){ 00028 IN1_=duty; 00029 IN2_=0; 00030 } 00031 else if (direction == BREAK) 00032 { 00033 IN1_=1; 00034 IN2_=1; 00035 } 00036 else 00037 { 00038 IN1_=0; 00039 IN2_=0; 00040 } 00041 }
Generated on Wed Jul 27 2022 20:12:06 by
1.7.2