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

Dependents:   SimplePIDBot

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HBridgeMotor.cpp Source File

HBridgeMotor.cpp

00001 #include "HBridgeMotor.h"
00002 
00003 HBridgeMotor::HBridgeMotor(PinName fin, PinName rin):fwd(fin), rev(rin) {
00004     power = 0.0;
00005 }
00006 
00007 void HBridgeMotor::set(float power) {
00008     if(power >= 0.0) {
00009         rev = 0.0;
00010         fwd = power;
00011     } else {
00012         rev = -power;
00013         fwd = 0.0;
00014     }
00015 }
00016 
00017 float HBridgeMotor::read() {
00018     return power;
00019 }