Adam Resnick / StepperMotors

Dependents:   CNCAirbrushCode

Revision:
0:3058939fa37c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stepper.cpp	Sat Apr 28 21:08:58 2012 +0000
@@ -0,0 +1,32 @@
+#include "Stepper.h"
+
+Stepper::Stepper(PinName step, PinName dir, PinName en) : _step(step), _dir(dir), _en(en) {
+    _step = 0, _dir = 0, _en = 1;
+    _position = 0;
+}
+
+void Stepper::stepOn(bool direction) {
+    _dir = direction;
+    if (direction) {
+        _position++;
+    } else {
+        _position--;
+    }
+    _step = 1;
+}
+
+void Stepper::stepOff(void) {
+    _step = 0;
+}
+
+void Stepper::enable(bool en) {
+    _en = !en;
+}
+
+void Stepper::setPosition(long position) {
+    _position = position;
+}
+
+long Stepper::getPosition(void) {
+    return _position;
+}
\ No newline at end of file