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

Dependents:   SimplePIDBot

Files at this revision

API Documentation at this revision

Comitter:
harryeakins
Date:
Tue Sep 20 12:54:36 2011 +0000
Commit message:
Initial version

Changed in this revision

HBridgeMotor.cpp Show annotated file Show diff for this revision Revisions of this file
HBridgeMotor.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HBridgeMotor.cpp	Tue Sep 20 12:54:36 2011 +0000
@@ -0,0 +1,19 @@
+#include "HBridgeMotor.h"
+
+HBridgeMotor::HBridgeMotor(PinName fin, PinName rin):fwd(fin), rev(rin) {
+    power = 0.0;
+}
+
+void HBridgeMotor::set(float power) {
+    if(power >= 0.0) {
+        rev = 0.0;
+        fwd = power;
+    } else {
+        rev = -power;
+        fwd = 0.0;
+    }
+}
+
+float HBridgeMotor::read() {
+    return power;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HBridgeMotor.h	Tue Sep 20 12:54:36 2011 +0000
@@ -0,0 +1,12 @@
+#include "mbed.h"
+
+class HBridgeMotor {
+public:
+    HBridgeMotor(PinName fin, PinName rin);
+    void set(float power);
+    float read();
+    
+private:
+    float power;
+    PwmOut fwd, rev;
+};
\ No newline at end of file