Yeongsoo Kim / Mbed 2 deprecated Mecha_DC_control

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motor.cpp Source File

Motor.cpp

00001 #include "Motor.h"
00002 
00003 Motor::Motor(PinName IN1, PinName IN2, PinName INH1, PinName INH2)
00004     : IN1_(IN1), IN2_(IN2), INH1_(INH1), INH2_(INH2)
00005 {
00006     INH1_=1;
00007     INH2_=1;
00008     IN1_.period_us(100);
00009     IN2_.period_us(100);
00010 }
00011 
00012 void Motor::setSpeed_percent(float percent, float direction)
00013 {
00014     float duty = percent/100.0;
00015     if(duty>1.0) {
00016         duty=1.0;
00017     } else if(duty<0.0) {
00018         duty=0.0;
00019     }
00020     if(direction==FORWARD) {
00021         IN1_=duty;
00022         IN2_=0;
00023     } else {
00024         IN1_=0;
00025         IN2_=duty;
00026 
00027     }
00028 }
00029