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
- Committer:
- tknara
- Date:
- 2016-01-19
- Revision:
- 1:727b2172d97c
- Parent:
- 0:0f53faf3b186
File content as of revision 1:727b2172d97c:
#include "Motor.h"
#include "mbed.h"
MOTOR::MOTOR(PinName PWM, PinName fwd, PinName rev ,float period ,int select):
pwm(PWM), cw(fwd), ccw(rev)
{
pwm.period(period);
if(select>1) {
mode = 1;
pwm = 0.5;
} else {
mode = 0;
pwm = 0;
cw = 0;
ccw = 0;
}
}
void MOTOR::speed(float speed)
{
if(mode == 0) {
cw = (speed > 0.0);
ccw = (speed < 0.0);
pwm = abs(speed);
} else if(mode > 0) {
pwm = 0.5+(speed*0.5);
}
}