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.
Actuator/Motor.cpp
- Committer:
- yeongsookim
- Date:
- 2019-11-03
- Revision:
- 0:3ead6014ad51
- Child:
- 1:d43df9a7cef2
File content as of revision 0:3ead6014ad51:
#include "Motor.h" Motor::Motor(PinName IN1, PinName IN2, PinName INH1, PinName INH2) : IN1_(IN1), IN2_(IN2), INH1_(INH1), INH2_(INH2) { INH1_=1; INH2_=1; IN1_.period_us(50); IN2_.period_us(50); } void Motor::setSpeed_percent(float percent, char direction) { float duty = percent/100.0; if(duty>1.0) { duty=1.0; } else if(duty<0.0) { duty=0.0; } if(direction==FORWARD) { IN1_=0; IN2_=duty; } else if (direction == BACKWARD){ IN1_=duty; IN2_=0; } else if (direction == BREAK) { IN1_=1; IN2_=1; } else { IN1_=0; IN2_=0; } }