Class library for a L298 H-Bridge to be used for motor control.

L298HBridge.cpp

Committer:
RiaanEhlers
Date:
2017-01-19
Revision:
1:6d242bb216d6
Parent:
0:39561fe6e4ff
Child:
2:1c000b6cf863

File content as of revision 1:6d242bb216d6:

#include "L298HBridge.h"
#include "mbed.h"
 
 
L298HBridge::L298HBridge(PinName ENPin, PinName FWDPin, PinName REVPin) : _ENPin(ENPin), _FWDPin(FWDPin), _REVPin(REVPin) {
    _ENPin = 0;     //PWM = 0%
    _FWDPin = 0;
    _REVPin = 0;
    _ENPin.period(0.020); //set PWM period to 20mS as default.
}
 
void L298HBridge::Fwd() {    
    _FWDPin = 1;
    _REVPin = 0;
}

void L298HBridge::Rev() {
    _FWDPin = 0;
    _REVPin = 1;
}

void L298HBridge::Stop() {
    _FWDPin = 0;
    _REVPin = 0;
}
 
void L298HBridge::Speed(int DutyPercent) {
    //_ENPin=(float)(DutyPercent/100);
    _ENPin = DutyPercent;
}