software to control a DC motor, preferably interfacing with a motor driver.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DCMotor.cpp Source File

DCMotor.cpp

00001 #include "DCMotor.h"
00002 #include "mbed.h"
00003 
00004 DCMotor::DCMotor(PinName PWMPin, PinName PinA, PinName PinB):
00005     _PWMPin(PWMPin), _PinA(PinA), _PinB(PinB) {
00006     
00007     _PWMPin.period(0.001);
00008     _PWMPin = 0;
00009     
00010     _PinA = 0;
00011     _PinB = 0;
00012 }
00013 
00014 void DCMotor::driveIt(float perCent) {
00015     if (perCent > 0) {
00016         _PinA = 0;
00017         _PinB = 1;
00018         
00019     } else {
00020         _PinA = 1;
00021         _PinB = 0;
00022     }
00023     _PWMPin = fabs(perCent/100);    
00024 }