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

Committer:
RiaanEhlers
Date:
Fri Jan 20 09:10:05 2017 +0000
Revision:
2:1c000b6cf863
Parent:
1:6d242bb216d6
V1.0

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 2:1c000b6cf863 27 void L298HBridge::Speed(float DutyPercent) {
RiaanEhlers 2:1c000b6cf863 28 _ENPin = DutyPercent /100;
RiaanEhlers 0:39561fe6e4ff 29 }