A simple class which can be used to control a motor through a HBridge (such as the L293).

Dependents:   SimplePIDBot

Committer:
harryeakins
Date:
Tue Sep 20 12:54:36 2011 +0000
Revision:
0:a3bcb7eab9d9
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
harryeakins 0:a3bcb7eab9d9 1 #include "HBridgeMotor.h"
harryeakins 0:a3bcb7eab9d9 2
harryeakins 0:a3bcb7eab9d9 3 HBridgeMotor::HBridgeMotor(PinName fin, PinName rin):fwd(fin), rev(rin) {
harryeakins 0:a3bcb7eab9d9 4 power = 0.0;
harryeakins 0:a3bcb7eab9d9 5 }
harryeakins 0:a3bcb7eab9d9 6
harryeakins 0:a3bcb7eab9d9 7 void HBridgeMotor::set(float power) {
harryeakins 0:a3bcb7eab9d9 8 if(power >= 0.0) {
harryeakins 0:a3bcb7eab9d9 9 rev = 0.0;
harryeakins 0:a3bcb7eab9d9 10 fwd = power;
harryeakins 0:a3bcb7eab9d9 11 } else {
harryeakins 0:a3bcb7eab9d9 12 rev = -power;
harryeakins 0:a3bcb7eab9d9 13 fwd = 0.0;
harryeakins 0:a3bcb7eab9d9 14 }
harryeakins 0:a3bcb7eab9d9 15 }
harryeakins 0:a3bcb7eab9d9 16
harryeakins 0:a3bcb7eab9d9 17 float HBridgeMotor::read() {
harryeakins 0:a3bcb7eab9d9 18 return power;
harryeakins 0:a3bcb7eab9d9 19 }