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

Committer:
RiaanEhlers
Date:
Thu Jan 19 12:34:48 2017 +0000
Revision:
1:6d242bb216d6
Parent:
0:39561fe6e4ff
Child:
2:1c000b6cf863
Testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RiaanEhlers 0:39561fe6e4ff 1 #include "L298HBridge.h"
RiaanEhlers 0:39561fe6e4ff 2 #include "mbed.h"
RiaanEhlers 0:39561fe6e4ff 3
RiaanEhlers 0:39561fe6e4ff 4
RiaanEhlers 0:39561fe6e4ff 5 L298HBridge::L298HBridge(PinName ENPin, PinName FWDPin, PinName REVPin) : _ENPin(ENPin), _FWDPin(FWDPin), _REVPin(REVPin) {
RiaanEhlers 0:39561fe6e4ff 6 _ENPin = 0; //PWM = 0%
RiaanEhlers 0:39561fe6e4ff 7 _FWDPin = 0;
RiaanEhlers 0:39561fe6e4ff 8 _REVPin = 0;
RiaanEhlers 1:6d242bb216d6 9 _ENPin.period(0.020); //set PWM period to 20mS as default.
RiaanEhlers 0:39561fe6e4ff 10 }
RiaanEhlers 0:39561fe6e4ff 11
RiaanEhlers 1:6d242bb216d6 12 void L298HBridge::Fwd() {
RiaanEhlers 1:6d242bb216d6 13 _FWDPin = 1;
RiaanEhlers 1:6d242bb216d6 14 _REVPin = 0;
RiaanEhlers 0:39561fe6e4ff 15 }
RiaanEhlers 0:39561fe6e4ff 16
RiaanEhlers 0:39561fe6e4ff 17 void L298HBridge::Rev() {
RiaanEhlers 1:6d242bb216d6 18 _FWDPin = 0;
RiaanEhlers 1:6d242bb216d6 19 _REVPin = 1;
RiaanEhlers 0:39561fe6e4ff 20 }
RiaanEhlers 0:39561fe6e4ff 21
RiaanEhlers 0:39561fe6e4ff 22 void L298HBridge::Stop() {
RiaanEhlers 1:6d242bb216d6 23 _FWDPin = 0;
RiaanEhlers 1:6d242bb216d6 24 _REVPin = 0;
RiaanEhlers 0:39561fe6e4ff 25 }
RiaanEhlers 0:39561fe6e4ff 26
RiaanEhlers 0:39561fe6e4ff 27 void L298HBridge::Speed(int DutyPercent) {
RiaanEhlers 1:6d242bb216d6 28 //_ENPin=(float)(DutyPercent/100);
RiaanEhlers 1:6d242bb216d6 29 _ENPin = DutyPercent;
RiaanEhlers 0:39561fe6e4ff 30 }